简体   繁体   中英

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?

Basically, you need functionality to do prefix matching on strings. Aerospike is primarily a key-value store which additionally supports secondary index queries. The secondary index query in Aerospike does not yet support prefix matching of strings. When this is supported, you can use Aerospike for your use case.

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

Autocomplete-Feature with Aerospike:

  1. Decide on a trigger count of characters (eg 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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM