开发者

MySQL Fulltext with particular word order

I am wondering if it is possible to do a MATCH() AGAINST() (fulltext) search in a way that words, who are not directly next to each other, need to be in a specific order? On my site, when users type words between double-quotes, the search will only display results that have those words in that particular order. For example, if this is the search term:

"pizza road"

it will return 'The best pizza down the road', but not 'the road to the best pizza'.

I know that BOOLEAN mode will allow for 'phrase' searches, but this me开发者_运维问答ans the words need to be next to each other (separated with just a space, period, comma, etc), which obviously won't return either of the results listed above: http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

Currently I am using regexp to perform this action, but needless to say that this is a bad way to search a varchar column (pointlessly fulltext indexed), even though it is just little under 200,000 rows. So what I would like to know is if it is possible to perform the same search using just MATCH() AGAINST()? Or should I combine it with with the regexp? Or is there even another method I haven't thought of?

I can provide table/ code samples upon request.

Thanks in advance!


Have you tried something like:

SELECT * 
FROM `table` 
WHERE MATCH(`first_column`) 
      AGAINST('+pizza +road' IN BOOLEAN MODE)
      HAVING `first_column` LIKE '%pizza %road%' 


Full text search, as typically implemented in relational databases, is a hack designed to provide only a very limited subset of expected functionality in an attempt to compete with better technology. Full text indexing is the Apple to RDBMS's Orange.

To be able to search using what amounts to a 'NEAR' operator as supported in traditional full text search engines, you would need to implement your own inverted index with positional meta data, which is how traditional search engines do it.

And while certainly possible, most developers would rather use a full text search engine to solve this problem, rather than expend the substantial effort needed to reinvent this wheel.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜