开发者

Efficient substring searching in Python with MySQL

I'm trying to implement a live search for my website. One that identifies words, or parts of a word, in a given string. The instant results are then underlined where they match the query.

For example, a query of "Fried green tomatoes" would yield:

SELECT * 
FROM articles 
WHERE (title LIKE '%fried%' OR
       title LIKE开发者_JAVA百科 '%green%' OR
       title LIKE '%tomatoes%)

This works perfectly with a very small dataset. However, once the number of records in the database increases, this query quickly becomes inefficient because it can't utilize indices.

I know this is technically what FULLTEXT searching in MySQL is for, but the quality of results just isn't as good.

What are some alternatives to get a very high quality substring search while keeping the query efficient?

Thanks.


Sphinx will help you to search fast within the huge amount of data


they are many FULLTEXT search engine that you can use like sphinx , Apache Solr, Whoosh (it's pure python) and Xapian. django-haystack (if you are using django) which can interface with the 3 last ones;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜