Storing search value in database

Not sure exactly what the issue is...

Create a model (say, SearchQueries) and whenever anybody hits your
search controller — presumably you only want to capture full queries
and not auto-complete requests – save the query into the database.

If you're using an autocomplete search which provides links direct to
particular pages, you may also need to capture these - probably by
appending a parameter to the address and making sure that you create
and save a search query when someone hits those pages straight from
the autocomplete list.