Is there any way to give extra ranking weight to a match if it contains a certain string?.
If there are multiple matching results which all contain the exact query string I would like to rank one of the rows higher than the others if a field contains a certain string.
For example, If I run the following querys I would like the United States to rank higher.
MySQL [(none)]> SELECT * FROM geolocations WHERE MATCH('@(country,state,county,city,state_code) "^san francisco$"/0.75') limit 10 OPTION field_weights=(country=10, state=9, county=4, city=2, state_code=9), ranker=SPH04;
+--------+--------------------+-------------------------+--------+---------------+--------------+------------+------------+-------------+
| id | country | state | county | city | country_code | state_code | latitude | longitude |
+--------+--------------------+-------------------------+--------+---------------+--------------+------------+------------+-------------+
| 84493 | Dominican Republic | Provincia de El Seibo | | San Francisco | DO | 8 | 18.850000 | -69.233299 |
| 85583 | El Salvador | Departamento de Morazan | | San Francisco | SV | MO | 13.697800 | -88.096497 |
| 85839 | Costa Rica | Provincia de Heredia | | San Francisco | CR | H | 10.003500 | -84.072098 |
| 86016 | Venezuela | Zulia | | San Francisco | VE | V | 10.650000 | -71.699997 |
| 86498 | Colombia | Cundinamarca | | San Francisco | CO | CUN | 4.977600 | -74.292900 |
| 87487 | Argentina | Cordoba | | San Francisco | AR | X | -31.428600 | -61.914299 |
| 88691 | Mexico | Nayarit | | San Francisco | MX | NAY | 20.902000 | -105.412804 |
| 106257 | United States | California | | San Francisco | US | CA | 37.779400 | -122.417603 |
+--------+--------------------+-------------------------+--------+---------------+--------------+------------+------------+-------------+
8 rows in set (0.001 sec)
MySQL [(none)]> SELECT * FROM geolocations WHERE MATCH('@(country,state,county,city,state_code) "^san diego$"/0.75') limit 10 OPTION field_weights=(country=10, state=9, county=4, city=2, state_code=9), ranker=SPH04;
+--------+---------------+------------------------+--------+-----------+--------------+------------+-----------+-------------+
| id | country | state | county | city | country_code | state_code | latitude | longitude |
+--------+---------------+------------------------+--------+-----------+--------------+------------+-----------+-------------+
| 86019 | Venezuela | Carabobo | | San Diego | VE | G | 10.264800 | -67.951698 |
| 86499 | Colombia | Departamento del Cesar | | San Diego | CO | CES | 10.339600 | -73.181000 |
| 96370 | United States | Texas | | San Diego | US | TX | 27.768700 | -98.248299 |
| 106254 | United States | California | | San Diego | US | CA | 32.799400 | -117.168602 |
+--------+---------------+------------------------+--------+-----------+--------------+------------+-----------+-------------+
4 rows in set (0.005 sec)
Similarly, I would like Ireland to rank higher with this query.
MySQL [(none)]> SELECT * FROM geolocations WHERE MATCH('@(country,state,county,city,state_code) "^dublin$"/0.75') limit 10 OPTION field_weights=(country=10, state=9, county=4, city=2, state_code=9), ranker=SPH04;
+--------+---------------+----------------------+--------+--------+--------------+------------+-----------+-------------+
| id | country | state | county | city | country_code | state_code | latitude | longitude |
+--------+---------------+----------------------+--------+--------+--------------+------------+-----------+-------------+
| 4222 | Belarus | Homyel’ Voblasc’ | | Dublin | BY | HO | 51.735001 | 30.327999 |
| 46584 | Ireland | Leinster | | Dublin | IE | L | 53.333099 | -6.248900 |
| 90439 | United States | Georgia | | Dublin | US | GA | 32.458099 | -82.936600 |
| 95912 | United States | Texas | | Dublin | US | TX | 32.090900 | -98.345497 |
| 96666 | United States | Virginia | | Dublin | US | VA | 37.105701 | -80.685303 |
| 101562 | United States | New Hampshire | | Dublin | US | NH | 42.895100 | -72.053398 |
| 103230 | United States | Ohio | | Dublin | US | OH | 40.110401 | -83.113098 |
| 103772 | United States | Pennsylvania | | Dublin | US | PA | 40.368198 | -75.201401 |
| 105810 | United States | California | | Dublin | US | CA | 37.720100 | -121.918999 |
| 109482 | Canada | Ontario | | Dublin | CA | ON | 43.507900 | -81.274696 |
+--------+---------------+----------------------+--------+--------+--------------+------------+-----------+-------------+
10 rows in set (0.004 sec)