I’m going to add simple live search to website (tips while entering text in input box).
Main task:
- 39k plain text lines for search into (~500 length of each line, 4Mb total size)
- 1k online users can simultaneously typing something in inputbox
- In some cases 2k-3k resuts can match user request
I’m worried about the following questions:
- Database VS textfile?
- Are there any general rules or best practices related to my task aimed for decreasing db/server memory load? (caching/indexing/etc)
- Do Sphinx/Solr are appropriate for such task?
Any links/advice will be extremely helpful.
Thanks
P.S. May be this is the best solution? PHP to search within txt file and echo the whole line
I have implemented ‘live search’ many times, always using AJAX with querying the database (MySQL) and haven’t had/observed any speed or large load issues yet.
Anyway I saw an implementations using Solr but cannot suggest whether it was quicker or consumed less resources.
It completely depends on the HW the server will run on, IMO. As I wrote somewhere, I had seen a server with very slow filesystem so implementing live search while reading and parsing from txt files (or using Solr) could be slower than when querying the database. On the other hand You can host on poor shared webhosting with slow DB connection (that gets even slower with more concurrent connections) so this won’t be the best solution.
My suggestion: use MySQL with AJAX (look at this jquery plugin or this article), set proper
INDEXes on the searched columns and if this is found slow You still can move to a txt file.