Ignore:
Timestamp:
Apr 20, 2013, 6:49:01 AM (11 years ago)
Author:
rvelices
Message:
 
Location:
extensions/rv_autocomplete
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_autocomplete/context_suggest.php

    r22246 r22304  
    4848});
    4949
     50// remove non filtering tags
     51$max = intval(0.9*count($context_image_ids));
     52while( count($tags) && $tags[0]['counter'] >= $max)
     53        array_shift($tags);
     54$tags = trigger_event('rvac_filter_context_tags', $tags);
     55
    5056$suggestions = array();
    5157foreach($tags as $tag)
    5258{
    53         if ($tag['counter']==count($context_image_ids))
    54                 continue;
    5559        $label = $tag['name'];
    5660
     
    97101})';
    98102
     103header("Content-Type: application/javascript; charset=".get_pwg_charset());
     104$expires = time() + 300;
     105header("Pragma:");
     106header("Cache-control: private, max-age=300");
     107header('Expires: '.gmdate('D, d M Y H:i:s', $expires).' GMT');
     108
    99109echo $js;
    100110
  • 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) {
  • extensions/rv_autocomplete/suggestions.php

    r22246 r22304  
    55
    66if (!defined('RVAC_ID')) {
    7   set_status_header(501);
    8   exit;
     7        set_status_header(501);
     8        exit;
    99}
    1010
     
    1616
    1717if (isset($_GET['txt'])) {
    18   foreach($data['src'] as $item)
    19     echo implode("\t", $item)."\n";
    20   exit;
     18        foreach($data['src'] as $item)
     19                echo implode("\t", $item)."\n";
     20        exit;
    2121}
    2222
    2323
    2424$ds = str_replace(
    25   array('\\/', '"q":', '"label":', '"value":', '"w":'),
    26   array('/', 'q:', 'label:', 'value:', 'w:'),
    27   json_encode($data['src']));
     25        array('\\/', '"q":', '"label":', '"value":', '"w":'),
     26        array('/', 'q:', 'label:', 'value:', 'w:'),
     27        json_encode($data['src']));
    2828$js = '$.extend(RVAC, {
    29   dataSource:'.$ds.',
    30   dataSourceAltLangIndex: '.$data['altLangIndex'].',
    31   roots: '.json_encode($data['roots']).',
    32   minForAltLang: 2,
    33   stopLookingAfter: 100,
    34   suggestions: 5,
    35   maxSuggestions: 10
     29        dataSource:'.$ds.',
     30        dataSourceAltLangIndex: '.$data['altLangIndex'].',
     31        roots: '.json_encode($data['roots']).',
     32        minForAltLang: 2,
     33        stopLookingAfter: 80,
     34        suggestions: 4,
     35        maxSuggestions: 8,
     36        minWeightForContextTrigger: 25
    3637});
    3738$.each(RVAC.dataSource, function(i,item) {
    38   item.q = item.q || item.label.toLowerCase()
     39        item.q = item.q || item.label.toLowerCase()
    3940});
    4041RVAC.start && RVAC.start();';
    4142
     43header("Content-Type: application/javascript; charset=".get_pwg_charset());
    4244echo $js;
    4345
Note: See TracChangeset for help on using the changeset viewer.