Changeset 22304 for extensions
- Timestamp:
- Apr 20, 2013, 6:49:01 AM (11 years ago)
- Location:
- extensions/rv_autocomplete
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rv_autocomplete/context_suggest.php
r22246 r22304 48 48 }); 49 49 50 // remove non filtering tags 51 $max = intval(0.9*count($context_image_ids)); 52 while( count($tags) && $tags[0]['counter'] >= $max) 53 array_shift($tags); 54 $tags = trigger_event('rvac_filter_context_tags', $tags); 55 50 56 $suggestions = array(); 51 57 foreach($tags as $tag) 52 58 { 53 if ($tag['counter']==count($context_image_ids))54 continue;55 59 $label = $tag['name']; 56 60 … … 97 101 })'; 98 102 103 header("Content-Type: application/javascript; charset=".get_pwg_charset()); 104 $expires = time() + 300; 105 header("Pragma:"); 106 header("Cache-control: private, max-age=300"); 107 header('Expires: '.gmdate('D, d M Y H:i:s', $expires).' GMT'); 108 99 109 echo $js; 100 110 -
extensions/rv_autocomplete/res/suggest-core.js
r22246 r22304 119 119 inew++; 120 120 } 121 121 122 122 var inp = $("#qsearchInput"); 123 123 if (data.length && inp.is(":focus")) { … … 191 191 } 192 192 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; 221 219 } 222 220 } 223 221 } 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 240 238 if (!RVAC.requestingContexts && this.options.rv.q.length > 1) { 241 239 var eligible = $.grep( res, function(item) { 242 240 if (item._matchIdx > 0 243 || item.w <= 25241 || item.w <= RVAC.minWeightForContextTrigger 244 242 || item.value === -1 245 243 || item.value[0]!="$" || item.value[1]!="t") … … 247 245 if (RVAC.requestedContexts.hasOwnProperty(item.value)) 248 246 return 0; 249 if (item.q.length - that.options.rv.q.length > 3)250 return 0;251 247 return 1; 252 248 } ); 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 } 253 266 254 267 if (eligible.length) { -
extensions/rv_autocomplete/suggestions.php
r22246 r22304 5 5 6 6 if (!defined('RVAC_ID')) { 7 8 7 set_status_header(501); 8 exit; 9 9 } 10 10 … … 16 16 17 17 if (isset($_GET['txt'])) { 18 19 20 18 foreach($data['src'] as $item) 19 echo implode("\t", $item)."\n"; 20 exit; 21 21 } 22 22 23 23 24 24 $ds = str_replace( 25 26 27 25 array('\\/', '"q":', '"label":', '"value":', '"w":'), 26 array('/', 'q:', 'label:', 'value:', 'w:'), 27 json_encode($data['src'])); 28 28 $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 36 37 }); 37 38 $.each(RVAC.dataSource, function(i,item) { 38 39 item.q = item.q || item.label.toLowerCase() 39 40 }); 40 41 RVAC.start && RVAC.start();'; 41 42 43 header("Content-Type: application/javascript; charset=".get_pwg_charset()); 42 44 echo $js; 43 45
Note: See TracChangeset
for help on using the changeset viewer.