Ignore:
Timestamp:
Apr 17, 2013, 6:20:18 AM (11 years ago)
Author:
rvelices
Message:

rv_autocomplete multi tags (need refinement)

Location:
extensions/rv_autocomplete
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/rv_autocomplete/functions.inc.php

    r22201 r22246  
    5757  if ($q != strtolower($l))
    5858    $ret['q'] = $q;
     59        if ($item['counter'] > 0)
     60                $ret['w'] = $item['counter'];
    5961  return $ret;
    6062}
  • extensions/rv_autocomplete/main.inc.php

    r22214 r22246  
    4545  global $template;
    4646
    47   $core_src = get_root_url().'plugins/'.RVAC_ID.'/res/suggest-core.js';
     47        $plug_root = get_root_url().'plugins/'.RVAC_ID.'/';
     48  $core_src = $plug_root.'res/suggest-core.js';
    4849
    4950  $data_src = rvac_get_data_file();
     
    5152    $data_src = get_root_url().$data_src;
    5253  else
    53     $data_src = get_root_url().'plugins/'.RVAC_ID.'/suggestions.php';
     54    $data_src = $plug_root.'suggestions.php';
    5455
    55   $fs = 'var RVAC={};
     56  $fs = 'var RVAC={root:"'.$plug_root.'"};
    5657$("#qsearchInput").one("focus", function() {
    5758var s;
  • extensions/rv_autocomplete/res/suggest-core.js

    r22201 r22246  
    9393}
    9494
     95RVAC.requestedContexts = {};
     96RVAC.requestingContexts = 0;
     97
     98RVAC.mergeData = function(data) {
     99        RVAC.requestingContexts--;
     100        var ctxq = data.ctxq + " "
     101                , ctxl = data.ctxl + " ";
     102        data = data.dataSource;
     103        $.each(data, function(i,item) {
     104                if (item.q)
     105                        item.q = ctxq + item.q;
     106                else
     107                        item.q = ctxq + item.label.toLowerCase();
     108                item.label = ctxl + item.label;
     109                item.ctx = 1;
     110        });
     111
     112        var ids=0, inew=0;
     113
     114        while (inew < data.length) {
     115                while (RVAC.dataSource[ids].w > data[inew].w)
     116                        ids++;
     117                RVAC.dataSource.splice(ids, 0, data[inew]);
     118                RVAC.dataSourceAltLangIndex++;
     119                inew++;
     120        }
     121       
     122        var inp = $("#qsearchInput");
     123        if (data.length && inp.is(":focus")) {
     124                inp.autocomplete("search");
     125        }
     126};
     127
    95128RVAC.start = function() {
    96129var $input = $("#qsearchInput");
     
    124157                        window.location = (url + (/\?/.test(url) ?  "&" : "?") + "acs=" + term);
    125158                }
    126                        
     159
    127160                return false;
    128161        },
     
    145178                        var item = RVAC.dataSource[i];
    146179                        if ( (item._matchIdx = item.q.search(matcher)) > -1 ) {
     180                                if (item.ctx && item._matchIdx>0)
     181                                        continue; // context searches only at beginning
    147182                                if (item.value !== -1) {
    148183                                        if (found.hasOwnProperty(item.value))
     
    157192
    158193                if (res.length > RVAC.suggestions) {//try filter
    159                         // compute number of matched "words" or "expression"
     194                        // compute number of matched "words" or "expressions"
    160195                        found={};
    161196                        var foundWords=0, word;
     
    202237                }
    203238
     239                var that = this;
     240                if (!RVAC.requestingContexts && this.options.rv.q.length > 1) {
     241                        var eligible = $.grep( res, function(item) {
     242                                if (item._matchIdx > 0
     243                                        || item.w <= 25
     244                                        || item.value === -1
     245                                        || item.value[0]!="$" || item.value[1]!="t")
     246                                        return 0;
     247                                if (RVAC.requestedContexts.hasOwnProperty(item.value))
     248                                        return 0;
     249                                if (item.q.length - that.options.rv.q.length > 3)
     250                                        return 0;
     251                                return 1;
     252                        } );
     253
     254                        if (eligible.length) {
     255                                item = eligible[0];
     256                                RVAC.requestedContexts[item.value] = 1;
     257                                RVAC.requestingContexts++;
     258                                var s=document.createElement("script");s.type="text/javascript";s.async=true;
     259                                s.src=RVAC.root+"context_suggest.php?context="+encodeURIComponent(item.value)+"&ctxq="+encodeURIComponent(item.q)+"&ctxl="+encodeURIComponent(item.label);
     260                                document.body.appendChild(s);
     261                        }
     262                }
     263
    204264                response( res );
    205265        }
  • extensions/rv_autocomplete/suggestions.php

    r22201 r22246  
    2323
    2424$ds = str_replace(
    25   array('\\/', '"q":', '"label":', '"value":'),
    26   array('/', 'q:', 'label:', 'value:'),
     25  array('\\/', '"q":', '"label":', '"value":', '"w":'),
     26  array('/', 'q:', 'label:', 'value:', 'w:'),
    2727  json_encode($data['src']));
    2828$js = '$.extend(RVAC, {
Note: See TracChangeset for help on using the changeset viewer.