如何创建包含匹配记录的良好搜索

发布于 2024-12-09 13:59:32 字数 3725 浏览 0 评论 0原文

我不知道如何在标题中解释这一点,当我搜索诸如 united Kingdom 之类的典型查询并且记录包含具有 < code>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 |
+--------------------+---------------+----------------+----------------+-----------------+---------------+------------+

如何做出返回非虚假数据的良好搜索查询?

I don't know how to explain this in the title, I'm experiencing a problem where I'm searching that when I search for a typical query such as united kingdom and records include records that have united states which I do not need it to be included in the query result, even when searching new york I get some records returned from york (in England).

Another, when searching maidstone, the query returns no records whatsoever, but in the database it exists.

I need to problem solve this query, it should search the rows matching the inputted query and remove them that match against the options -- when I say options, I mean as rec.column_name = etc....

When searching 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 ) 

When searching 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 )

This is the overall records in the table:

+--------------------+---------------+----------------+----------------+-----------------+---------------+------------+
| 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 |
+--------------------+---------------+----------------+----------------+-----------------+---------------+------------+

How do I make a good search query that returns non-false data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2024-12-16 13:59:32

将搜索字符串放在双引号内:'"united Kingdom"' 以实现完全匹配。

如果您想搜索两个单词,但不一定彼此相邻,可以使用 + 运算符:'+united +kingdom'

请注意,如果您对搜索列使用二进制排序规则,则搜索将区分大小写。

Put the search string inside double quotes: '"united kingdom"' for an exact match.

If you want to search for both words, but not necessarily adjacent to each other, you can use the + operator: '+united +kingdom'.

Note that the searches will be case sensitive if you use a binary collation for the columns you search in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文