开发者

How can I match "laptop" and "laptops" when search for "laptop" is performed using MySQL's match...against full-text search?

开发者 https://www.devze.com 2022-12-19 08:14 出处:网络
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.

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.

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.

My SQL looks something like this:

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.


use the wildcard * on the end of your phrase

SELECT * FRO... WHERE MATCH(table.field1, table.field2, table.field3) AGAINST ('laptop*') IN BOOLEAN MODE)


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.


If you're using MySQL 5.1, you can install a stemmer plugin.

  • http://forge.mysql.com/projects/project.php?id=215
  • http://forge.mysql.com/projects/project.php?id=42


Or you can use a dedictaed "indexable" field and pre-stem the content (and search query). The snowball project has stemmers for multiple languages.

0

精彩评论

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