seperman / fast-autocomplete

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

Extension to phrases with variables #17

Open ksmithra opened 4 years ago

ksmithra commented 4 years ago

Thanks for the wonderful package. I am exploring if this package can be extended to support typeahead where the phrases can have variables in them. Enumeration all possible values for those variables may be ruled out. For example consider below phrases: host {host_name} is from {location_name} hello {host_name} etc. wherein the values for {host_name} and {location_name} would come from an external lookup database. Is it possible to achieve this with the data structure used in the package? Thanks much for any help.

seperman commented 4 years ago

Hi @ksmithra There are some pieces of the original package that I never open sourced and would make it easier to achieve what you are describing. If you checkout https://fair.com where this package is used for the autocomplete you can see some example. For example type bmw in santa or bmw in santa monica and see the autocomplete results. The homepage doesn't show all the results from autocomplete but if you click search and go to a page like https://www.fair.com/cars/used/bmw-in-santa-monica you can see up to 5 results from autocomplete when typing.

Now getting back to how you can use this package to do what you want, you can add words like this:

Then when typing host you should get host foo and host bar in the results. once you type host foo is from it should five you both host foo is from los angeles and host foo is from paris

You can see an example video of how this can be translated to something like Lucene query language to return search results from Elasticsearch here: https://zepworks.com/posts/you-autocomplete-me/#demo-2

Note that the part that converts the results into Lucene query is not open sourced.