Ignore:
Timestamp:
Apr 20, 2013, 6:49:01 AM (11 years ago)
Author:
rvelices
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_autocomplete/res/suggest-core.js

    r22246 r22304  
    119119                inew++;
    120120        }
    121        
     121
    122122        var inp = $("#qsearchInput");
    123123        if (data.length && inp.is(":focus")) {
     
    191191                }
    192192
    193                 if (res.length > RVAC.suggestions) {//try filter
    194                         // compute number of matched "words" or "expressions"
    195                         found={};
    196                         var foundWords=0, word;
    197                         for (i=0; i<res.length; i++) {
    198                                 word = res[i]._matchWord = ac_match_word( res[i], this.options.rv.q );
    199                                 if (!found.hasOwnProperty(word)) {
    200                                         foundWords++;
    201                                         found[word]=1;
    202                                         if (foundWords == RVAC.maxSuggestions)
    203                                                 res = res.slice(0, i+1);
    204                                 }
    205                                 else
    206                                         found[word]++;
    207                         }
    208 
    209                         if (foundWords==1)
    210                                 res = res.slice(0, RVAC.maxSuggestions);
    211                         else if (foundWords > RVAC.suggestions) {
    212                                 for (i=1; i<foundWords; i++) {
    213                                         word = res[i]._matchWord;
    214                                         if ( found[word] > 1 ) {
    215                                                 for (j=i-1; j>=0; j--) {
    216                                                         if (res[j]._matchWord == word) {
    217                                                                 res.splice(i--, 1);
    218                                                                 found[word]--;
    219                                                                 break;
    220                                                         }
     193                // compute number of matched "words" or "expressions"
     194                found={};
     195                var foundWords=0, word;
     196                for (i=0; i<res.length; i++) {
     197                        word = res[i]._matchWord = ac_match_word( res[i], this.options.rv.q );
     198                        if (!found.hasOwnProperty(word)) {
     199                                foundWords++;
     200                                found[word]=1;
     201                                if (foundWords == RVAC.maxSuggestions)
     202                                        res = res.slice(0, i+1);
     203                        }
     204                        else
     205                                found[word]++;
     206                }
     207
     208                if (foundWords==1)
     209                        res = res.slice(0, RVAC.maxSuggestions);
     210                else if (foundWords > RVAC.suggestions) {
     211                        for (i=1; i<foundWords; i++) {
     212                                word = res[i]._matchWord;
     213                                if ( found[word] > 1 ) {
     214                                        for (j=i-1; j>=0; j--) {
     215                                                if (res[j]._matchWord == word) {
     216                                                        res.splice(i--, 1);
     217                                                        found[word]--;
     218                                                        break;
    221219                                                }
    222220                                        }
    223221                                }
    224                                 res = res.slice(0, foundWords);
    225                         }
    226                         else {
    227                                 for (i=res.length-1; i>=0 && res.length > RVAC.suggestions; i--) {
    228                                         word = res[i]._matchWord;
    229                                         for (j=i-1; j>=0; j--) {
    230                                                         if (res[j]._matchWord == word) {
    231                                                                 res.splice(i, 1);
    232                                                                 break;
    233                                                         }
    234                                         }
    235                                 }
    236                         }
    237                 }
    238 
    239                 var that = this;
     222                        }
     223                        res = res.slice(0, foundWords);
     224                }
     225                else {
     226                        for (i=res.length-1; i>=0 && res.length > RVAC.suggestions; i--) {
     227                                word = res[i]._matchWord;
     228                                for (j=i-1; j>=0; j--) {
     229                                                if (res[j]._matchWord == word) {
     230                                                        res.splice(i, 1);
     231                                                        break;
     232                                                }
     233                                }
     234                        }
     235                }
     236
     237                // check for multi tags
    240238                if (!RVAC.requestingContexts && this.options.rv.q.length > 1) {
    241239                        var eligible = $.grep( res, function(item) {
    242240                                if (item._matchIdx > 0
    243                                         || item.w <= 25
     241                                        || item.w <= RVAC.minWeightForContextTrigger
    244242                                        || item.value === -1
    245243                                        || item.value[0]!="$" || item.value[1]!="t")
     
    247245                                if (RVAC.requestedContexts.hasOwnProperty(item.value))
    248246                                        return 0;
    249                                 if (item.q.length - that.options.rv.q.length > 3)
    250                                         return 0;
    251247                                return 1;
    252248                        } );
     249
     250                        if (eligible.length==1) {
     251                                if (res.length > RVAC.suggestions || foundWords>1) {
     252                                        if (this.options.rv.q.length <= eligible[0].q.length/2 )
     253                                                eligible.length = 0;
     254                                }
     255                        }
     256                        else {
     257                                for (i=0; i<eligible.length; i++)
     258                                        if (this.options.rv.q.length == eligible[i].q.length) {
     259                                                eligible = [ eligible[i] ];
     260                                                break;
     261                                        }
     262
     263                                if (eligible.length > 1)
     264                                        eligible.length = 0;
     265                        }
    253266
    254267                        if (eligible.length) {
Note: See TracChangeset for help on using the changeset viewer.