I'm trying to build a search feature in to my website. Searching is the primary purpose of the site and I am having a few issues with the MySQL search feature.
我正在尝试在我的网站上构建搜索功能。搜索是网站的主要目的,我在MySQL搜索功能方面遇到了一些问题。
I would like to be able to search with a single search string against multiple text fields.
我希望能够针对多个文本字段使用单个搜索字符串进行搜索。
I'm using MySQL's match...against statements to perform a full-text search. I'm running this in Boolean mode.
我正在使用MySQL的匹配...对语句执行全文搜索。我在布尔模式下运行它。
My SQL looks something like this:
我的SQL看起来像这样:
SELECT * FROM ...
WHERE MATCH(table.field1, table.field2, table.field3)
AGAINST ('laptop' IN BOOLEAN MODE)
Currently this returns results that have the word laptop
but not if they have the word laptops
.
目前,这将返回具有“笔记本电脑”一词的结果,但如果它们具有“笔记
I need it to return results that contain the word laptop
or laptops
.
我需要它来返回包含笔记本电脑或笔记本电脑一词的结果。
4 个解决方案
#1
1
If your requirements are more general, requiring full stemming support e.g. matching "testing" or "tests" against test in the full text index for example then you can use an alternative full text index plugin. A google search pulls up a number of possibilities although a quick glance suggests that most are commercial rather than open source.
如果您的要求更为一般,则需要完全支持,例如例如,在全文索引中将“测试”或“测试”与测试匹配,然后您可以使用替代的全文索引插件。谷歌搜索提出了许多可能性,虽然快速浏览表明大多数是商业而非开源。
#2
2
use the wildcard *
on the end of your phrase
在短语的末尾使用通配符*
SELECT * FRO... WHERE MATCH(table.field1, table.field2, table.field3) AGAINST ('laptop*') IN BOOLEAN MODE)
#3
1
If you're using MySQL 5.1, you can install a stemmer plugin.
如果您使用的是MySQL 5.1,则可以安装一个stemmer插件。
- http://forge.mysql.com/projects/project.php?id=215
- http://forge.mysql.com/projects/project.php?id=215
- http://forge.mysql.com/projects/project.php?id=42
- http://forge.mysql.com/projects/project.php?id=42
#4
0
Or you can use a dedictaed "indexable" field and pre-stem the content (and search query). The snowball project has stemmers for multiple languages.
或者,您可以使用专用的“可索引”字段并预先阻止内容(和搜索查询)。雪球项目有多种语言的词干表。
#1
1
If your requirements are more general, requiring full stemming support e.g. matching "testing" or "tests" against test in the full text index for example then you can use an alternative full text index plugin. A google search pulls up a number of possibilities although a quick glance suggests that most are commercial rather than open source.
如果您的要求更为一般,则需要完全支持,例如例如,在全文索引中将“测试”或“测试”与测试匹配,然后您可以使用替代的全文索引插件。谷歌搜索提出了许多可能性,虽然快速浏览表明大多数是商业而非开源。
#2
2
use the wildcard *
on the end of your phrase
在短语的末尾使用通配符*
SELECT * FRO... WHERE MATCH(table.field1, table.field2, table.field3) AGAINST ('laptop*') IN BOOLEAN MODE)
#3
1
If you're using MySQL 5.1, you can install a stemmer plugin.
如果您使用的是MySQL 5.1,则可以安装一个stemmer插件。
- http://forge.mysql.com/projects/project.php?id=215
- http://forge.mysql.com/projects/project.php?id=215
- http://forge.mysql.com/projects/project.php?id=42
- http://forge.mysql.com/projects/project.php?id=42
#4
0
Or you can use a dedictaed "indexable" field and pre-stem the content (and search query). The snowball project has stemmers for multiple languages.
或者,您可以使用专用的“可索引”字段并预先阻止内容(和搜索查询)。雪球项目有多种语言的词干表。