【问题标题】:laravel full-text search with multiple keywords togetherlaravel 全文搜索,多个关键字放在一起
【发布时间】:2015-08-24 04:48:12
【问题描述】:

我正在构建一个 laravel 项目搜索字段,我在其中使用全文搜索。我已经设法让它工作,但我无法同时搜索多个关键字。
例子: 我有一个值为one two three four 的行,如果我搜索two three,它会找到其中包含twothree 的所有条目。但我希望它同时找到twothree 的条目

SQL 查询:

DB::raw("select id, name, text, image, publishDate from game
where match (name) AGAINST ('*$searchphrase*' IN BOOLEAN MODE) LIMIT 5")

【问题讨论】:

  • 或者最终如果可以对其进行排序,以便包含两个关键字的短语列在顶部。

标签: php mysql laravel search full-text-search


【解决方案1】:

请看这个:http://goo.gl/lZIKBkhttps://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

“+”代表与

“-”代表NOT

[无运算符]暗示或

您没有任何暗示“或”的运算符。


【讨论】:

  • 我最初尝试过:使用“+”,但似乎没有任何区别。尝试在 $searchphrase 前后使用“+”。
  • 在搜索词组之间尝试“+”。比如“+apple +banana +orange”。
  • 让它工作了 :) 我只在 where 中使用了比赛。最终按相关性排序,它奏效了。结果是这样的:选择 Id、Name、Text、Image、PublishDate、match(Name) against ('$searchphrase') 作为游戏的相关性,其中 match (Name) AGAINST ('+*$searchphrase*' IN BOOLEAN MODE) AND status = 1 order by Relevance desc LIMIT 5" 虽然现在似乎我可以用不完整的词搜索,如“upgr”找到升级但“等级”不会找到“升级”
猜你喜欢
  • 2014-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-20
相关资源
最近更新 更多