且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在多个表格列中搜索多个术语?

更新时间:2022-12-22 22:30:49

布尔模式

BOOLEAN MODE

SELECT * FROM contacts WHERE  
MATCH(firstname,lastname,email,webpage,country,city,street...)  
AGAINST('+bob +jenkins' IN BOOLEAN MODE)

布尔模式非常强大.它甚至可以满足我的所有需求.我将不得不做一些测试.通过将+放在搜索词的前面,这些词成为必需的. (该行必须匹配"bob"和"jenkins",而不是"bob"或"jenkins").此模式甚至适用于非索引列,因此尽管它会更慢(这是我需要测试的速度),但我可以在视图上使用它.我遇到的最后一个问题是,它与部分搜索词不匹配,因此"bob"将找不到"bobby".通常的%通配符不起作用,而是使用星号*.

Boolean mode is very powerful. It might even fulfil all my needs. I will have to do some testing. By placing + in front of the search terms those terms become required. (The row must match 'bob' AND 'jenkins' instead of 'bob' OR 'jenkins'). This mode even works on non-indexed columns, and thus I can use it on a view although it will be slower (that is what I need to test). One final problem I had was that it wasn't matching partial search terms, so 'bob' wouldn't find 'bobby' for example. The usual % wildcard doesn't work, instead you use an asterisk *.