Answer the question
In order to leave comments, you need to log in
How is search caching implemented?
The site has a flexible ajax search, you can adjust the price with a slider, from which to which, search by category, tags 20+, a few more additional parameters and, of course, search by request.
So the question is brewing - how to optimize this whole thing? Store every single request in the db or cache with redis?
There are many search parameters, the user will change only one, and the result will change dramatically. It's not even that the requests are complex, no, the problem lies in frequent calls to the server.
How are such problems solved in serious projects?
Answer the question
In order to leave comments, you need to log in
How are such problems solved in serious projects?
Search is divided into 2 types: static (search by clear match) and dynamic (search by fuzzy match).
We perform in 2 stages:
1. First - search for a clear match, (int, boolean) =>
[list of parameters: int, bool & etc.] => ID: cache1
2. Then from this list - search for a fuzzy (varchar ). =>
varchar +ID:cache1=>ID:cache2
Now, if the text search query has not changed, but only the settings have changed, the search is performed through a reverse reverse search, and if someone has already searched for such a combination (it is in cache1), then the result will be received almost instantly.
It is possible to form a client selection (cache table), excluding the just changed parameter from the cache1 (but keeping the search string) and transfer the selection result to the client, so that in the future (if the user moves the price "slider", for example, without changing the search query ), search already locally on the client itself without a request to the server.
In serious projects, in-memory search is done. Sphinx, Elastic Search, etc.
Well, the server is set up one for which frequent calls are not a problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question