Typeahead.js code as is will look for prefix matches, as you correctly say. There is a "trick" though: every datum may also contain a tokens
element, which as the Typeahead documentation says is "a collection of strings that aid typeahead.js in matching datums with a given query".
The prefix matching is done against tokens
. If you don't supply a tokens
value for one of your datums, its value is tokenized (space-separated) for you. However, you could supply tokens
to get what you want. For example, in your case you would supply a value of tokens
that is all the unique substrings of all the words in your query string.
I suggest "all unique substrings of length >= 2", btw.