I’m trying to build a live search function for a knowledge base plugin so that as soon as a user types something into the search field possible results are loaded below the search field as close to real time as possible.
If possible, I’d like to avoid hitting the database with ajax. Instead, I’d like to store possible results in an array and search this array instead of the database.
Does anyone have any idea how best to do this? Ideally, I don’t want to build the array in real time, I think it should be a batch process that occurs each time the user saves a knowledge base item (this is a custom post type that I’ve created).
So, for example, the array can be built and then stored in a single database field that’s loaded as and when the live search is displayed.
I have some questions:-
1) Do you think that storing results in an array rather than hitting the database is a feasible approach?
2) Do you have any suggestions as to the best approach of building this array. Should it occur on save, or perhaps it should be triggered by a “Build knowledge base index” button? Which do you think will be best for the end user?