Ignore:
Timestamp:
03/10/15 14:16:28 (9 years ago)
Author:
emanuel.dima@uni-tuebingen.de
Message:
  1. beta-27: more results, bug fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • SRUAggregator/trunk/src/main/resources/assets/js/search.js

    r6081 r6092  
    22(function() {
    33"use strict";
     4
     5var NO_MORE_RECORDS_DIAGNOSTIC_URI = "info:srw/diagnostic/1/61";
    46
    57window.MyAggregator = window.MyAggregator || {};
     
    6567                corpus.priority = 1; // used for ordering search results in corpus view
    6668                corpus.index = index; // original order, used for stable sort
    67         });
    68         this.recurse(function(corpus, index) {
    69                 if (corpus.institution.link > 1) {
    70                         corpus.selected = false;
    71                 }
    7269        });
    7370}
     
    180177
    181178        nohits: {
    182                 requests: [],
    183                 results: [],
     179                results: null,
    184180        },
    185181        anyLanguage: [multipleLanguageCode, "Any Language"],
     
    249245                });
    250246        },
     247        nextResults: function(corpusId) {
     248                // console.log("searching next results in corpus:", corpusId);
     249                this.props.ajax({
     250                        url: 'rest/search/'+this.state.searchId,
     251                        type: "POST",
     252                        data: {
     253                                corpusId: corpusId,
     254                                numberOfResults: this.state.numberOfResults,
     255                        },
     256                        success: function(searchId, textStatus, jqXHR) {
     257                                // console.log("search ["+query+"] ok: ", searchId, jqXHR);
     258                                var timeout = 250;
     259                                setTimeout(this.refreshSearchResults, timeout);
     260                                this.setState({ searchId: searchId, timeout: timeout });
     261                        }.bind(this),
     262                });
     263        },
    251264
    252265        refreshSearchResults: function() {
     
    258271                        success: function(json, textStatus, jqXHR) {
    259272                                var timeout = this.state.timeout;
    260                                 if (json.requests.length > 0) {
     273                                if (json.inProgress) {
    261274                                        if (timeout < 10000) {
    262275                                                timeout = 1.5 * timeout;
     
    267280                                        console.log("search ended; hits:", json);
    268281                                }
    269                                 this.setState({ hits: json, timeout: timeout });
     282                                var corpusHit = this.state.zoomedCorpusHit;
     283                                if (corpusHit) {
     284                                        for (var resi = 0; resi < json.results.length; resi++) {
     285                                                var res = json.results[resi];
     286                                                if (res.corpus.id === corpusHit.corpus.id) {
     287                                                        corpusHit = res;
     288                                                        break;
     289                                                }
     290                                        }
     291                                }
     292                                this.setState({ hits: json, timeout: timeout, zoomedCorpusHit: corpusHit});
    270293                        }.bind(this),
    271294                });
     
    293316                this.state.corpora.setVisibility(this.state.searchLayerId,
    294317                        languageFilter === 'byGuess' ? multipleLanguageCode : languageObj[0]);
    295                 this.setState({language: languageObj, languageFilter: languageFilter});
    296                 this.state.corpora.update();
     318                this.setState({
     319                        language: languageObj,
     320                        languageFilter: languageFilter,
     321                        corpora: this.state.corpora, // === this.state.corpora.update();
     322                });
    297323        },
    298324
    299325        setLayer: function(layerId) {
    300326                this.state.corpora.setVisibility(layerId, this.state.language[0]);
    301                 this.state.corpora.update();
    302                 this.setState({searchLayerId: layerId});
     327                this.setState({
     328                        searchLayerId: layerId,
     329                        hits: this.nohits,
     330                        searchId: null,
     331                        corpora: this.state.corpora, // === this.state.corpora.update();
     332                });
    303333        },
    304334
     
    319349                var noLangFiltering = this.state.languageFilter === 'byMeta';
    320350                var langCode = this.state.language[0];
    321                 return this.state.hits.results.map(function(corpusHit) {
    322                         return {
    323                                 corpus: corpusHit.corpus,
    324                                 startRecord: corpusHit.startRecord,
    325                                 endRecord: corpusHit.endRecord,
    326                                 exception: corpusHit.exception,
    327                                 diagnostics: corpusHit.diagnostics,
    328                                 searchString: corpusHit.searchString,
    329                                 kwics: noLangFiltering ? corpusHit.kwics :
    330                                         corpusHit.kwics.filter(function(kwic) {
    331                                                 return kwic.language === langCode || langCode === multipleLanguageCode || langCode === null;
    332                                         }),
    333                         };
    334                 });
     351                var results = null, inProgress = 0, hits = 0;
     352                if (this.state.hits.results) {
     353                        results = this.state.hits.results.map(function(corpusHit) {
     354                                return {
     355                                        corpus: corpusHit.corpus,
     356                                        inProgress: corpusHit.inProgress,
     357                                        exception: corpusHit.exception,
     358                                        diagnostics: corpusHit.diagnostics,
     359                                        kwics: noLangFiltering ? corpusHit.kwics :
     360                                                corpusHit.kwics.filter(function(kwic) {
     361                                                        return kwic.language === langCode ||
     362                                                               langCode === multipleLanguageCode ||
     363                                                               langCode === null;
     364                                                }),
     365                                };
     366                        });
     367                        for (var i = 0; i < results.length; i++) {
     368                                var result = results[i];
     369                                if (result.inProgress) {
     370                                        inProgress++;
     371                                }
     372                                if (result.kwics.length > 0) {
     373                                        hits ++;
     374                                }
     375                        }
     376                }
     377                return {
     378                        results: results,
     379                        hits: hits,
     380                        inProgress: inProgress,
     381                };
    335382        },
    336383
     
    354401        },
    355402
    356         handleChange: function(event) {
     403        onQuery: function(event) {
    357404                this.setState({query: event.target.value});
    358405        },
     
    377424        },
    378425
    379         renderAggregator: function() {
     426        render: function() {
    380427                var layer = layerMap[this.state.searchLayerId];
    381428                return  (
     
    390437                                                        React.createElement("input", {className: "form-control input-lg search", name: "query", type: "text",
    391438                                                                value: this.state.query, placeholder: this.props.placeholder,
    392                                                                 tabIndex: "1", onChange: this.handleChange, onKeyDown: this.handleKey}),
     439                                                                tabIndex: "1", onChange: this.onQuery, onKeyDown: this.handleKey}),
    393440                                                        React.createElement("div", {className: "input-group-btn"},
    394441                                                                React.createElement("button", {className: "btn btn-default input-lg", type: "button", onClick: this.search},
     
    467514                                React.createElement(Modal, {ref: "resultModal", title: this.renderZoomedResultTitle(this.state.zoomedCorpusHit)},
    468515                                        React.createElement(ZoomedResult, {corpusHit: this.state.zoomedCorpusHit,
     516                                                                  nextResults: this.nextResults,
    469517                                                                  getDownloadLink: this.getDownloadLink,
    470518                                                                  getToWeblichtLink: this.getToWeblichtLink,
     
    475523
    476524                                React.createElement("div", {className: "top-gap"},
    477                                         React.createElement(Results, {requests: this.state.hits.requests,
    478                                                          results: this.filterResults(),
     525                                        React.createElement(Results, {collhits: this.filterResults(),
    479526                                                         toggleResultModal: this.toggleResultModal,
    480527                                                         getDownloadLink: this.getDownloadLink,
     
    485532                        );
    486533        },
    487         render: function() {
    488                 return this.renderAggregator();
    489         }
    490534});
    491535
     
    622666        },
    623667
    624         renderDiagnostic: function(d) {
    625                 return  React.createElement("div", {className: "alert alert-warning", key: d.uri},
     668        renderDiagnostic: function(d, key) {
     669                if (d.uri === NO_MORE_RECORDS_DIAGNOSTIC_URI) {
     670                        return false;
     671                }
     672                return  React.createElement("div", {className: "alert alert-warning", key: key},
    626673                                        React.createElement("div", null, "Diagnostic: ", d.message)
    627674                                );
     
    632679                        return false;
    633680                }
    634 
    635681                return corpusHit.diagnostics.map(this.renderDiagnostic);
    636682        },
     
    714760                                        React.createElement("li", null,
    715761                                                error ?
    716                                                         React.createElement("div", {className: "alert alert-danger", style: {margin:10}}, error) :
     762                                                        React.createElement("div", {className: "alert alert-danger", style: {margin:10, width:200}}, error) :
    717763                                                        React.createElement("a", {href: this.props.getToWeblichtLink(corpusId), target: "_blank"}, " ",
    718764                                                                "Send to Weblicht")
     
    729775        propTypes: {
    730776                corpusHit: PT.object,
     777                nextResults: PT.func.isRequired,
    731778                languageMap: PT.object.isRequired,
    732779                weblichtLanguages: PT.array.isRequired,
     
    737784        mixins: [ResultMixin],
    738785
     786        getInitialState: function() {
     787                return {
     788                        inProgress: false,
     789                };
     790        },
     791
     792        componentWillReceiveProps: function() {
     793                this.setState({inProgress: false});
     794        },
     795
     796        nextResults: function(e) {
     797                this.setState({inProgress: true});
     798                this.props.nextResults(this.props.corpusHit.corpus.id);
     799        },
     800
    739801        renderLanguages: function(languages) {
    740802                return languages
     
    742804                                .sort()
    743805                                .join(", ");
     806        },
     807
     808        renderMoreResults:function(){
     809                if (this.state.inProgress || this.props.corpusHit.inProgress)
     810                        return React.createElement("span", {style: {fontStyle:'italic'}}, "Retrieving results, please wait...");
     811
     812                var moreResults = true;
     813                for (var i = 0; i < this.props.corpusHit.diagnostics.length; i++) {
     814                        var d = this.props.corpusHit.diagnostics[i];
     815                        if (d.uri === NO_MORE_RECORDS_DIAGNOSTIC_URI) {
     816                                moreResults = false;
     817                                break;
     818                        }
     819                }
     820                if (!moreResults)
     821                        return React.createElement("span", {style: {fontStyle:'italic'}}, "No other results available for this query");
     822                return  React.createElement("button", {className: "btn btn-default", onClick: this.nextResults},
     823                                        React.createElement("span", {className: "glyphicon glyphicon-option-horizontal", 'aria-hidden': "true"}), " More Results"
     824                                );
    744825        },
    745826
     
    777858
    778859                                                React.createElement("div", {style: {textAlign:'center', marginTop:10}},
    779                                                         React.createElement("button", {className: "btn btn-default"},
    780                                                                 React.createElement("span", {className: "glyphicon glyphicon-option-horizontal", 'aria-hidden': "true"}), " More Results"
    781                                                         )
     860                                                         this.renderMoreResults()
    782861                                                )
    783862
     
    789868var Results = React.createClass({displayName: 'Results',
    790869        propTypes: {
    791                 requests: PT.array.isRequired,
    792                 results: PT.array.isRequired,
     870                collhits: PT.object.isRequired,
    793871                searchedLanguage: PT.array.isRequired,
    794872                toggleResultModal: PT.func.isRequired,
     
    825903        },
    826904
    827         renderProgressMessage: function(hits) {
    828                 var total = this.props.requests.length + this.props.results.length;
    829                 var msg = hits + " matching collections found in " + this.props.results.length + " searched collections";
    830                 var percents = Math.round(100 * this.props.results.length / total);
     905        renderProgressMessage: function() {
     906                var collhits = this.props.collhits;
     907                var done = collhits.results.length - collhits.inProgress;
     908                var msg = collhits.hits + " matching collections found in " + done + " searched collections";
     909                var percents = Math.round(100 * collhits.hits / collhits.results.length);
    831910                var styleperc = {width: percents+"%"};
    832911                return  React.createElement("div", {style: {marginTop:10}},
    833912                                        React.createElement("div", null, msg),
    834                                         this.props.requests.length > 0 ?
     913                                        collhits.inProgress > 0 ?
    835914                                                React.createElement("div", {className: "progress", style: {marginBottom:10}},
    836915                                                        React.createElement("div", {className: "progress-bar progress-bar-striped active", role: "progressbar",
     
    847926
    848927        render: function() {
    849                 if (this.props.results.length + this.props.requests.length === 0) {
     928                var collhits = this.props.collhits;
     929                if (!collhits.results) {
    850930                        return false;
    851931                }
    852                 var hits = this.props.results.filter(function(corpusHit) { return corpusHit.kwics.length > 0; }).length;
    853                 var showprogress = this.props.requests.length > 0;
     932                var showprogress = collhits.inProgress > 0;
    854933                return  React.createElement("div", null,
    855934                                        React.createElement(ReactCSSTransitionGroup, {transitionName: "fade"},
    856                                                  showprogress ? this.renderProgressMessage(hits) : React.createElement("div", {style: {height:20}}),
     935                                                 showprogress ? this.renderProgressMessage() : React.createElement("div", {style: {height:20}}),
    857936                                                React.createElement("div", {style: {marginBottom:2}},
    858937                                                         showprogress ? false :
    859                                                                 React.createElement("div", {className: "float-left"}, " ", hits + " matching collections found", " "),
     938                                                                React.createElement("div", {className: "float-left"}, " ", collhits.hits + " matching collections found", " "),
    860939                                                       
    861                                                          hits === 0 ? false :
     940                                                         collhits.hits === 0 ? false :
    862941                                                                React.createElement("div", {className: "float-right"},
    863942                                                                        React.createElement("div", null,
    864943                                                                                 this.renderDisplayKWIC(),
    865                                                                                  this.props.requests.length === 0 ?
     944                                                                                 collhits.inProgress === 0 ?
    866945                                                                                        React.createElement("div", {className: "inline"}, " ", this.renderDownloadLinks(), " ")
    867946                                                                                        :false
     
    872951                                                        React.createElement("div", {style: {clear:'both'}})
    873952                                                ),
    874                                                 this.props.results.map(this.renderResultPanel)
     953                                                collhits.results.map(this.renderResultPanel)
    875954                                        )
    876955                                );
Note: See TracChangeset for help on using the changeset viewer.