FullText 或 LIKE 搜索问题(无法找到库存)
Issue with FullText or LIKE search (unable to find inventory)
当用户搜索我知道在库存中的物品时,在我的库存中查找物品时遇到一些问题。
Table 列是 ManufacturerNameMatch、SubCategoryNameMatch、MainCategoryNameMatch、Model_Name
当我搜索 Nikon Ti-E 时,脚本似乎找不到它。但是,我知道它在库存中。在数据库中,Model_Name 列为 "Eclipse Ti-E w/HUBC Inverted Phase Contrast",ManufacturerNameMatch 为 'Nikon'
我正在使用 FullTextSearch 索引进行多词搜索,但似乎无法找到它,所以我一直在拼接列并使用 LIKE 搜索(仍然没有)。想知道是否有人有更好的想法,或者我做错了什么或不理解 FullTextIndex 搜索或 LIKE 搜索 MySQL。
$category = 'Nikeon Ti-E'
$findPhraseMatch = DB::table('inventory')
->selectRaw(DB::raw("*, GROUP_CONCAT(CambridgeID) as `CambridgeIDArray`, count(*) as `groupTotal`"))
->where(DB::raw("CONCAT_WS(' ', ManufacturerNameMatch, SubCategoryNameMatch, MainCategoryNameMatch, Model_Name)"), 'LIKE', "%$category%")
->where('Units_OnHand', '>=', 1)
->groupBy('Model_Name', 'ManufacturerNameMatch')
->orderBy('ManufacturerNameMatch')
->paginate(15);
在此处进行全文搜索
// $final would look like +nikon +ti+e
$findFullMatch = DB::table('inventory')
->selectRaw(DB::raw("*, GROUP_CONCAT(CambridgeID) as `CambridgeIDArray`, count(*) as `groupTotal`"))
->whereRaw("MATCH(ManufacturerNameMatch, SubCategoryNameMatch, MainCategoryNameMatch, Model_Name, Title_Override, Description_Old) AGAINST ('$final' IN BOOLEAN MODE) AND Units_OnHand >= 1")
like
运算符无法通过这种方式找到您要查找的内容,因为连接的文本不包含 Nikeon Ti-E
子字符串。还有一个拼写错误,不过这个可能只能在SO这里拼错了。
如果您想使用 like
运算符,则必须搜索 like '%Nikon% Ti-E%'
(注意 Nikon 和 Ti-E 之间的额外百分比)。
对此,使用全文搜索可能是更合适的解决方案。我会使用 Boolean mode,您可以在其中指定两个词都应该在连接的内容中,以便出现在结果中。
... where match(ManufacturerNameMatch, SubCategoryNameMatch, MainCategoryNameMatch, Model_Name) against ('+Nikon +"Ti-E"' in boolean mode)
当用户搜索我知道在库存中的物品时,在我的库存中查找物品时遇到一些问题。
Table 列是 ManufacturerNameMatch、SubCategoryNameMatch、MainCategoryNameMatch、Model_Name
当我搜索 Nikon Ti-E 时,脚本似乎找不到它。但是,我知道它在库存中。在数据库中,Model_Name 列为 "Eclipse Ti-E w/HUBC Inverted Phase Contrast",ManufacturerNameMatch 为 'Nikon'
我正在使用 FullTextSearch 索引进行多词搜索,但似乎无法找到它,所以我一直在拼接列并使用 LIKE 搜索(仍然没有)。想知道是否有人有更好的想法,或者我做错了什么或不理解 FullTextIndex 搜索或 LIKE 搜索 MySQL。
$category = 'Nikeon Ti-E'
$findPhraseMatch = DB::table('inventory')
->selectRaw(DB::raw("*, GROUP_CONCAT(CambridgeID) as `CambridgeIDArray`, count(*) as `groupTotal`"))
->where(DB::raw("CONCAT_WS(' ', ManufacturerNameMatch, SubCategoryNameMatch, MainCategoryNameMatch, Model_Name)"), 'LIKE', "%$category%")
->where('Units_OnHand', '>=', 1)
->groupBy('Model_Name', 'ManufacturerNameMatch')
->orderBy('ManufacturerNameMatch')
->paginate(15);
在此处进行全文搜索
// $final would look like +nikon +ti+e
$findFullMatch = DB::table('inventory')
->selectRaw(DB::raw("*, GROUP_CONCAT(CambridgeID) as `CambridgeIDArray`, count(*) as `groupTotal`"))
->whereRaw("MATCH(ManufacturerNameMatch, SubCategoryNameMatch, MainCategoryNameMatch, Model_Name, Title_Override, Description_Old) AGAINST ('$final' IN BOOLEAN MODE) AND Units_OnHand >= 1")
like
运算符无法通过这种方式找到您要查找的内容,因为连接的文本不包含 Nikeon Ti-E
子字符串。还有一个拼写错误,不过这个可能只能在SO这里拼错了。
如果您想使用 like
运算符,则必须搜索 like '%Nikon% Ti-E%'
(注意 Nikon 和 Ti-E 之间的额外百分比)。
对此,使用全文搜索可能是更合适的解决方案。我会使用 Boolean mode,您可以在其中指定两个词都应该在连接的内容中,以便出现在结果中。
... where match(ManufacturerNameMatch, SubCategoryNameMatch, MainCategoryNameMatch, Model_Name) against ('+Nikon +"Ti-E"' in boolean mode)