3
我有以下的數據庫模式,作爲一個例子:使用MySQL全文搜索匹配部分單詞?
CREATE TABLE IF NOT EXISTS `items` (
`id` int(11) unsigned NOT NULL,
`irn` varchar(30) NOT NULL,
`name` varchar(225) NOT NULL,
`description` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `name_desc_irn` (`name`,`description`,`irn`),
FULLTEXT KEY `name` (`name`),
FULLTEXT KEY `description` (`description`),
FULLTEXT KEY `irn` (`irn`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
,後面的數據(假設這裏的數據被簡化,在現實中我有超過10萬條記錄)
id name irn description
1 Widget A ABC12345 testing ABC12345
2 Widget B ABC-12345 the ABC is great
而下面查詢:
SELECT
items.id as id,
items.irn as irn,
items.name as name,
(
((MATCH (irn) AGAINST ('12345')) * 5) +
((MATCH (name) AGAINST ('12345')) * 4) +
((MATCH (description) AGAINST ('12345')) * 3) +
(MATCH(name, description, irn) AGAINST ('12345'))
) AS relevance
FROM
items
WHERE
MATCH(name, description, irn) AGAINST ('*12345' IN BOOLEAN MODE)
HAVING
relevance > 0
ORDER BY
relevance DESC
第二個結果(ABC-12345的irn)被返回,但不是第一個(ABC12345)。爲什麼它不符合ABC12345,但確實符合ABC-12345?有沒有什麼辦法可以使它與全文搜索匹配?如果不是,搜索12345時發現ABC12345和ABC-12345的搜索類型最適合的方式是什麼?