Browse Source

hack hack hack

pull/378/head
Peter Johnson 9 years ago
parent
commit
22fa0d0458
  1. 40
      query/autocomplete.js

40
query/autocomplete.js

@ -14,6 +14,11 @@ var ngrams = function( vs ){
var ngrams_last_only = function( vs ){ var ngrams_last_only = function( vs ){
// hack to disable ngrams when query parsing enabled
if( vs.var('parsed_text').get() ){
return null;
}
var name = vs.var('input:name').get(); var name = vs.var('input:name').get();
var vs2 = new peliasQuery.Vars( vs.export() ); var vs2 = new peliasQuery.Vars( vs.export() );
@ -34,18 +39,23 @@ var phrase = function( vs ){
var phrase_first_only = function( vs ){ var phrase_first_only = function( vs ){
var name = vs.var('input:name').get(); // hack to disable substr when query parsing enabled
var s = name.split(' '); if( !vs.var('parsed_text').get() ){
// single token only, abort var name = vs.var('input:name').get();
if( s.length < 2 ){ var s = name.split(' ');
return function(){ return null; };
}
var vs2 = new peliasQuery.Vars( vs.export() ); // single token only, abort
vs2.var('input:name').set( name.substr(0, name.lastIndexOf(' ') ) ); if( s.length < 2 ){
return null;
}
return phrase( vs2 ); var vs2 = new peliasQuery.Vars( vs.export() );
vs2.var('input:name').set( name.substr(0, name.lastIndexOf(' ') ) );
return phrase( vs2 );
}
return phrase( vs );
}; };
var simpleNgramsView = function( vs ){ var simpleNgramsView = function( vs ){
@ -123,12 +133,20 @@ query.score( peliasQuery.view.population( simpleNgramsView ) );
function generateQuery( clean ){ function generateQuery( clean ){
var vs = new peliasQuery.Vars( defaults ); var vs = new peliasQuery.Vars( defaults );
vs.var( 'parsed_text', false );
// remove single grams at end // remove single grams at end
clean.text = clean.text.replace(/( .$)/g,'').trim(); var text = clean.text.replace(/( .$)/g,'').trim();
if( clean.hasOwnProperty('parsed_text') ){
if( clean.parsed_text.hasOwnProperty('name') ){
vs.var( 'parsed_text', true );
text = clean.parsed_text.name;
}
}
// input text // input text
vs.var( 'input:name', clean.text ); vs.var( 'input:name', text );
// always 10 (not user definable due to caching) // always 10 (not user definable due to caching)
vs.var( 'size', 10 ); vs.var( 'size', 10 );

Loading…
Cancel
Save