gpt4 book ai didi

mysql - Laravel 5 中的全文搜索

转载 作者:行者123 更新时间:2023-11-29 06:29:10 25 4
gpt4 key购买 nike

我对 Laravel 中的全文搜索有疑问。

我在各个列中应用了索引。

我有一个关键字

bar soap

现在我需要按以下顺序进行记录。

  • 肥皂
  • 肥皂 block
  • 酒吧
  • 肥皂

我的查询在这里

select `inventories`.*, MATCH (title, short_description, brand, long_description, inventory_code, product_code) AGAINST ('bar soap' IN BOOLEAN MODE) as score from `inventories` where MATCH (title, short_description, brand, long_description, inventory_code, product_code) AGAINST ('bar soap' IN BOOLEAN MODE) order by `score` desc

我也评论了这个doc .

您的帮助将不胜感激。

最佳答案

尝试这样的事情:

    // Text
$search = 'bar soap';
$parsedSearch = explode(' ', 'bar soap');

// Create pattern
$patterns = [];
$patterns[] = $search; // bar soap
$patterns[] = $parsedSearch[1] . ' ' . $parsedSearch[0]; // soap bar
$patterns[] = $parsedSearch[0]; //bar
$patterns[] = $parsedSearch[1]; //soap


// Set Query
$query = "select `inventories`.*, MATCH (title, short_description, brand, long_description, inventory_code, product_code) AGAINST ('bar soap' IN BOOLEAN MODE) as score from `inventories` where MATCH (title, short_description, brand, long_description, inventory_code, product_code) AGAINST ('bar soap' IN BOOLEAN MODE) order by field(`score`," . implode(',', $patterns) . ")";

return $query;

您可能想要创建一个函数来创建模式以支持其他搜索,然后使用 MySQL ORDER BY FIELD 函数对其进行排序。

关于mysql - Laravel 5 中的全文搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57489244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com