Implementing search history and suggestion

Hi I am trying to implement simple search functionality for my app.
I just used ilike function for this.

Then I want to keep user’s search history and want to implement search suggestion.
But I actually don’t know where to start.

First, create search_terms table with term and counter.
Whenever user tries to search, check if that term is already in the database,
if yes, increase counter by 1, if not, save that term in database with counter = 1

For search term suggestion,

query = from st in SearchTerm, order_by: [desc: st.counter], limit: 10


  1. SearchTerm table will be filled with meaningless word or words like asdasd3 or else
  2. Words with wrong spelling will be saved also(aple, orenge…)
  3. SearchTerm table will be anyway getting bigger very soon.

And also maybe I have a performance issue?

So Can you guys give me some advice?

You didn’t say which DB you are using but if it’s Postgres, it has some addons that help with searching. You can check here as a start. Quick Google search showed me this as well.

Outside of that there’s Elastic which is pretty much the standard. There are many others.

I think you’ll have to reach way outside your database to get adequate searching functionality.