Background:
I am using typeahead.js to surface search suggestions to users. I want users want to be able to see suggestions based off both the "title" & "diff" of my dataset. The issue I'm having is that when the title & diff fields overlap, it can lead to some confusing results.
In this image you can see that active query is "Ea" and typehead is surfacing suggestions for both the title "Earthbound" & the diff "Easy". I do not like this result, I would instead like a queries with less than 3 characters to only pull from the "title" field.
Question:
How can I set a unique minLength for each datumtokenizer in my dataset? So that suggestions pull from titles starting on the first character and suggestions don't start pulling from the "diff" until the query has at least 3 characters.
Code:
var games = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title', 'diff'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: 'https://api.myjson.com/bins/ss93y'
);
$('.basic .typeahead').typeahead({
hint: false,
highlight: true,
minLength: 1,
limit: 5,
}, {
name: 'games',
display: 'title',
source: games,
templates: {
header: '<h3 class="games-header">Games</h3>'
}
});
JS Fiddle: https://jsfiddle.net/n3my5r8u/