如何使用python mysql实现搜索引擎?
我有一个使用自定义 Python 脚本创建的 MySQL 数据库。我需要对数据库中的表实现全文搜索。我可以使用 SELECT * FROM myTable WHERE (title LIKE '%hello%' OR title LIKE '%world%'),但是我不认为这是实现搜索的非常有效的方法,因为表中的数据有近百万行。
我正在使用 innoDB 表,因此内置的 MySQL 全文搜索 MyISAM 将不起作用。有关方法或教程的任何建议可以为我指明正确的方向吗?
I have a MySQL database created using a custom Python script. I need to implement full-text search on a table in the database. I can use SELECT * FROM myTable WHERE (title LIKE '%hello%' OR title LIKE '%world%')
, however I don't think that is a very efficient way of implementing search since the data in the table has nearly one million rows.
I am using innoDB tables so the built in MySQL full text search for MyISAM will not work. Any suggestions on methods or tutorials that will point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的数据内容类似于您可以使用某些全文搜索特定引擎,例如 Lucene:
http://lucene.apache .org/pylucene/
如果你正在使用 Django,那么你有 Haystack:
http://haystacksearch.org/
Solr也是一个全文检索相关技术你可能会读到:
http://wiki.apache.org/solr/SolPython
If your data is content like you could use some full-text search specific engine like Lucene:
http://lucene.apache.org/pylucene/
If you are doing Django you have Haystack:
http://haystacksearch.org/
Solr is also a full-text search related technology you might read about:
http://wiki.apache.org/solr/SolPython
我不是 MySQL 专家,但我可以立即说,您不应该选择与某个值类似的所有内容。如果用户输入“and”,并且有数千个结果,那么最好从数据库中选择一定数量,然后在用户转到下一页(例如)时使用 LIMIT 参数加载更多结果。
因此,要回答您的问题,查询效率不高,您应该使用我上面建议的内容。
I am no expert with MySQL, but I can immediately say that you should not be selecting everything that is like to a value. If the user types in "and", and there are thousands of results, it may be better just to select a certain amount from the database and then load more using the LIMIT parameter when the user goes to the next page (e.g).
So to answer your question, the query is not efficient, and you should use something like I suggested above.
看一下:使用 InnoDB 进行全文搜索。他们建议使用外部搜索引擎,因为在 innoDB 表中没有真正好的搜索选项。
Take a look at: Fulltext Search with InnoDB. They suggest using an external search engine since there is no really good option to search within innoDB tables.