Search code examples
cachingautocompleteaerospike

Aerospike autocompletion


I want to implement an autocompletion mechanism for aerospike but I don't how I cando it .Is it possible to make an autocompletion mechanism with aerospike? If yes how can it be implemented?


Solution

  • Already deployed one with existing feature set. It works roughly like this:

    Autocomplete-Feature with Aerospike:

    1. Decide on a trigger count of characters (e.g. 3, 'prefixlength')
    2. Filter any input to get only ascii characters (no é,ä,ü,..), trim all whitespaces and transform to lowercase.
    3. Create records for all possible combinations from "Autocomplete_aaa" to "Autocomplete_zzz", each with a list (would use large ordered list to be on the safe side) OR handle not existing records in your query-logic.
    4. In each list, gather all strings you want to propose when the prefix is entered.
    5. Anytime a user enters something, cut it to prefixlength and just query the record 'Autocomplete_car' for it to propose 'cars', 'car repair', and so on.
    6. From now on just use that list to filter further on the client side (e.g. javascript).

    The main takeaway from this is that you will have to reduce both your results and your search terms to the same identifying token (here 3 ascii characters) that will act as your primary key for records.

    Note: this won't scale indefinetely in terms of list size. You need to choose your prefix-length carefully, so there ain't too many proposals that need to be read from db and transfered to the client but also watch out for Aerospike's max record size if not using an large, infinitely scalable data type like the large list.