J
J
jasonOk2016-05-15 17:35:04
PHP
jasonOk, 2016-05-15 17:35:04

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

3 answer(s)
S
Sergey, 2016-05-15
Protko @Fesor

How are such problems solved in serious projects?

No way. Optimize the search itself, using data denormalization to simplify the search as much as possible and make it as less stressful for the server as possible. Well, in order to "reduce" the number of requests, "tricks" like throttle / debounce on the client are used, so that not every mouse click sends a request, but when the user has not been active, for example, for a second.
Partially this problem can be solved by HTTP caching. That is, all search parameters go to queryString, which means that we can have the desired page / data by one URI. However, the varmat of such a cache will take a long time, and the complexity of the invalidation will be so high that you need to think 10 times before deciding on this.

X
xmoonlight, 2016-05-15
@xmoonlight

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.

C
ComodoHacker, 2016-05-16
@ComodoHacker

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 question

Ask a Question

731 491 924 answers to any question