How To Make Twitter Typeahead Exact Match Words and Phrases -


twitters typeahead matches word anywhere in phrase search "car" results can come phrase second word matches "car". instance when searching car in list business card. business card appears , worse appears before car. ie:

search term: car suggestions: business card car car pool carbon 

i want more google , twitter (they never suggest isn't matching typed beginning) typed word relevant, car more relevant when typing car business card.

i want stop matching second word until types space , starts second word. in above example business card not appear in list unless typed:

business c 

how can stop behavior of matching , suggesting words aren't exact match start of typed search.

another way how stop typeahead tokenizing or splitting on space. typeahead matches start of word (^), if space wasn't recognized word boundary work more google , twitters users expect.

thanks help, tyler

update 1.

i updated dataset return datum has value , token typeahead _transformdatum method not tokenize tokens splitting on space. works great , works desired:

values: apple, great ape

search term: ap suggestions: apple

this want. there new issue.

issue: when using search term space no suggestions returned.

so when type "great " suggestions stop type space.:

search term: great (with space) suggestions: (none)

i'm thinking tokens can not have spaces. though documentation doesn't explicitly in issue:

the canonical form of datum object value property , tokens property. value string represents underlying value of datum , tokens collection of strings aid typeahead.js in matching datums given query.

you can

$('.typeahead').typeahead({source:myarray, matcher: function(item){     var reg = new regexp('^'+this.query);     if( item.match(reg) ) return true;     else return false;  }}) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -