2
我不知道如何在标题解释这一点,我遇到一个问题,我在寻找,当我搜索如united kingdom
和记录一个典型的查询包括具有united states
,我并不需要它被包含在查询结果中搜索new york
甚至当记录,我得到返回从york
(英格兰)的一些记录。如何创造一个良好的搜索,包括匹配记录
另外,搜索maidstone
时,该查询返回任何记录任何,但在数据库中它的存在。
我需要解决这个问题,它应该搜索匹配输入查询的行,并删除它们与选项匹配 - 当我说选项时,我的意思是rec.column_name = etc...
。
当搜索united kingdom
:
WHERE (MATCH (rec.street_name, rec.city, rec.state, rec.country) AGAINST ('united kingdom' IN BOOLEAN MODE)
OR (rec.street_name = 'united kingdom'
OR rec.city = 'united kingdom'
OR rec.state = 'united kingdom'
OR rec.country = 'united kingdom'
)
) AND (rec.visible_listing = 1 AND rec.marked_delete = 0 AND rec.is_archive = 0)
当搜索maidstone
:
WHERE (MATCH (rec.street_name, rec.city, rec.state, rec.country) AGAINST ('maidstone' IN BOOLEAN MODE)
OR (rec.street_name = 'maidstone'
OR rec.city = 'maidstone'
OR rec.state = 'maidstone'
OR rec.country = 'maidstone'
)
) AND (rec.visible_listing = 1 AND rec.marked_delete = 0 AND rec.is_archive = 0)
这是在表中总记录:
+--------------------+---------------+----------------+----------------+-----------------+---------------+------------+
| street_name | city | state | country | visible_listing | marked_delete | is_archive |
+--------------------+---------------+----------------+----------------+-----------------+---------------+------------+
| Mill Hill | Dover | Kent | United Kingdom | 1 | 0 | 0 |
| Penmaes | Rhayader | Powys | United Kingdom | 1 | 0 | 0 |
| Essex St | Jersey City | Hudson | United States | 1 | 0 | 0 |
| Vesey St | New York | New York | United States | 1 | 0 | 0 |
| E Broadway | Manhattan | New York | United States | 1 | 0 | 0 |
| Cowdray Square | Dover | Kent | United Kingdom | 1 | 0 | 1 |
| Falsgrave Crescent | York | England | United Kingdom | 1 | 0 | 0 |
| Tait Ave | Sanger | California | United States | 1 | 0 | 0 |
| Morton Ave | Parsons | Kansas | United States | 1 | 0 | 0 |
| N Washington St | Clinton | Missouri | United States | 1 | 0 | 0 |
| Lower Barngoose | Carn Brea | Cornwall | United Kingdom | 1 | 0 | 0 |
| Moorwell Dr | Shepherdswell | Kent | United Kingdom | 1 | 0 | 0 |
| Elm Grove | Maidstone | Kent | United Kingdom | 1 | 0 | 0 |
| Manse Rd | Killin | Stirling | United Kingdom | 1 | 0 | 0 |
| Muirkirk Dr | Glasgow | Glasgow City | United Kingdom | 1 | 0 | 0 |
| Alveston Ave | Harrow | Greater London | United Kingdom | 1 | 0 | 0 |
+--------------------+---------------+----------------+----------------+-----------------+---------------+------------+
我如何做一个优秀的搜索查询返回非错误数据?
为什么你经常结合起来使用FULLTEXT搜索网站搜索吗? – GolezTrol
这是什么意思? – MacMac
WHERE之后的第一行是MATCH条件,只能在具有FULLTEXT索引的字段上使用。下面以OR开头的行是检查完全匹配的常规条件(检查字段是否包含文字字符串)。将这些结合起来看起来并不有用。 – GolezTrol