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?
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.