开发者

How can I cut off results in a full-text (boolean mode) search?

开发者 https://www.devze.com 2023-04-07 21:31 出处:网络
I\'m using a boolean mode full-text search: SELECT *, match(Tournament.Name) against (\'query\' in boolean mode) as score FROM `tournaments` AS `Tournament` WHERE 1 =1 ORDER BY `score` desc LIMIT 20

I'm using a boolean mode full-text search:

SELECT *, match(Tournament.Name) against ('query' in boolean mode) as score FROM `tournaments` AS `Tournament` WHERE 1 =1 ORDER BY `score` desc LIMIT 20

What I wanted to do was to change the where clause to contain something li开发者_运维百科ke score > 0.5, but this threw an error about score being an unknown column.

Is there a way around this? Or is my method flawed?


EDIT: For example, say I search for "cheese", I get the following results:

  • Cheese is great
  • I love cheese
  • Cheese ftw
  • Cake is nice too
  • Anyone for a cuppa?

The query has successfully sorted the matches to the top (they have good scores), but the others (with scores of 0) are left in the result set. I want to filter out these low scoring results.


Rick James answered this over at the MySQL dev forums.

He wrote:

"score" is derived, so it cannot be in WHERE. Use HAVING instead of WHERE in this situation

SELECT ... AS score
FROM ...
WHERE ...
HAVING score > 0.5
ORDER BY score DESC


I suggest you have a look at the basic mysql functions, to extract substrings from strings and convert them into a number. You can use them in you were clause and compare the result to 0.5

0

精彩评论

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

关注公众号