seperman / fast-autocomplete

Fast Autocomplete: When Elastcsearch suggestions are not fast and flexible enough
MIT License
271 stars 40 forks source link

How to enable partial matching when user types final words of entity without initial ones? #26

Open AndreaSottana opened 3 years ago

AndreaSottana commented 3 years ago

One of the feature of the repository, as mentioned in the README, is that

Elasticsearch's Autocomplete suggestor does not handle any sort of combination of the words you have put in. For example Fast Autocomplete can handle 2018 Toyota Camry in Los Angeles when the words 2018, Toyota Camry, Los Angeles are seperately fed into it. While Elasticsearch's autocomplete needs that whole sentence to be fed to it to show it in Autocomplete results.

However, I would like to know if there is an easy way to achieve the opposite, i.e. if an "entity" (let's call it a word in the context of this repository, even though it's technically made up by multiple words) is searched by typing only the final words that make up this entity, how do we get autocomplete to retrieve it correctly?

As an example, let's take this

from fast_autocomplete import AutoComplete
words = {'anti money laundering': {}, 'notification letter': {}, 'lending institution': {}}
autocomplete = AutoComplete(words=words)
print(autocomplete.search(word='laundering'))

this would return an empty list []. Is there a way to enable recognition of "anti money laundering" as a single item when the user only types the final word "laundering"? Likewise, if I do

print(autocomplete.search(word='le'))

I would want to see [['notification letter'], ['lending institution']] as results instead of just "lending institution". Not sure if this feature exists, if so, could you explain how to enable it? If it doesn't exist, have you ever considered adding it as a feature?

seperman commented 3 years ago

Hi @AndreaSottana These are some features that I have not got the permissions to opensource yet. The easiest thing to do is to also feed those individual words to fast_autocomplete. So something like this:

words = {'anti money laundering': {'label': 'anti money laundering'}, 'notification letter': {'label': ''notification letter'}, 'laundering': {'label': 'anti money laundering'}}

By doing so once fast_autocomplete returns the results, you use the labels to show the final results to the user. You will probably end up having some logic after that to maybe show more options. Maybe label is a list of items and you use some other algorithm to decide which one of those to show to the user.

AndreaSottana commented 3 years ago

Thanks @seperman will do as you suggest!