Join GitHub today
Completion prefix suggestion #3376
Note: This is an experimental feature!
Traditionally FST suggesters needed to create an in-memory structure upfront, which needed to be in sync with the data inserted/deleted. This step to create a FST can be really expensive and long lasting on production systems.
So, why not trying to create an efficient FST alike structure on index time, load that quickly into memory and use this for suggestions?
Before deep diving into implementation details, let's start with a small sample
Create a simple mapping
A request looks like this
This is the response
As you can see, the text returned is the provided output during indexing. Also the payload is included, which might carry a reference ID to the artist and thus makes it easy to retrieve further information.
In order to support prefix suggestion the field has to be marked as type
If you want to return payloads, you have to explicitely enable them by using
In addition, you can set
Preserve position increments
You can set
The most simple case to index is like this
Depending on the analyzer used
Defining an output will always return the output for a found suggestion.
You should define custom weights instead of relying on the default one (see the drawbacks section). The weight must be an positive integer (no float) and defines the order of your suggestions.
Also custom weights can make your suggestions valuable. Using weights you could boost the most played song or the best rated hotel first in your suggestions.
Searches are working exactly like the phrase and term suggesters
Using term frequency as default weight
If you do not specify a weight, the term frequency is used. This only makes sense if you optimize to a single segment or have large segments. If you do not, having custom weights might yield the results you are awaiting. So using term frequences as a weight indicator is not the best solution and you should set weight yourself.