简体   繁体   中英

Is IndexedDB suitable for providing suggestions as user types input

Currently I have a website with an input element with an event listener that is fired by the input event. Any new input results in an Ajax request where an SQL query is made, which uses the LIKE keyword to find all records which have the contents of the input element as a substring. There can be as many as over a million records in the SQLite database.

I would like this to work for users when they are off line, so I have thought about using IndexedDB storage so they could download the data to their device when online and then use the system when they are offline. I did read at https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Basic_Terminology that

The API does not have an equivalent of the LIKE operator in SQL.

I have almost no experience in any databases other than SQL types. I would like to find out before getting too involved whether the IndexedDB API would be suitable for achieving the type of auto suggestion feature for user input that I have described.

IndexedDB essentially only allows you to retrieve objects by primary key or by a property that you have specifically created an index for. These will be exact match or range match lookups. You can't look inside strings for substring matches.

However, this does not mean that you should not use IndexedDB to store your data. It just means that you need a layer on top such as Elasticlunr.js which will build a search index. You can rebuild that index every time the database changes, and persist that search index to the database.

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