1

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?

  • What's the scope of the search? Titles only? Excerpt? Or entire content/meta fields too? – TheDeadMedic Mar 29 '14 at 13:33
  • I need the title and a very short excerpt - enough to show the first line of the content to give the user an idea of what the help topic is about. – Paul McCarthy Mar 30 '14 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.