我有一个城市和州的数据库(大约 43,000 个)。我对它进行全文搜索,如下所示:
select city, state, match(city, state_short, state) against (:q in boolean mode) as score
from zipcodes where
match(city, state_short, state) against (:q in boolean mode)
group by city, state order by score desc limit 6
当我:q
用有意义的字符串替换时,它可以工作,但假设我搜索houston texas
,我希望结果是第一个,但它是第 3 个:
North Houston, Texas
South Houston, Texas
Houston, Texas
我怎样才能使Houston, Texas
体重比其他两个重?这显然对于其他类似的城市也应该是一样的。
编辑
这行得通,有什么想法吗?
SELECT * FROM (
SELECT city, state, MATCH(city, state_short, state) AGAINST (:q IN BOOLEAN MODE) as score
FROM zipcodes
WHERE MATCH(city, state_short, state) AGAINST (:q IN BOOLEAN MODE)
GROUP BY city, state
ORDER BY score DESC LIMIT 6
) AS tbl
ORDER BY score DESC, LENGTH(city)