0

I have just set up a full text index on my MySQL database, but unfortunately it's not returning any results.

This seems to be a common issue, and the typical answers are use the MyISAM engine, and the 'IN BOOLEAN MODE' function. Well neither of these seem to work for me.

Here is my example code:

DROP TABLE IF EXISTS parentregionlist;
CREATE TABLE parentregionlist
(
    RegionID INT NOT NULL,
    RegionType VARCHAR(50),
    RelativeSignificance VARCHAR(3),
    SubClass VARCHAR(50),
    RegionName VARCHAR(255),
    RegionNameLong VARCHAR(510),
    ParentRegionID INT,
    ParentRegionType VARCHAR(50),
    ParentRegionName VARCHAR(255),
    ParentRegionNameLong VARCHAR(510),
    CountryCode VARCHAR(2),
  TimeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (RegionID),
    FULLTEXT (RegionNameLong)
) ENGINE = MyISAM;

INSERT INTO parentregionlist
VALUES (575, 
"City", 
"", 
"", 
"Birmingham", 
"Birmingham, England, United kingdom", 
6023342, 
"Multi-City (Vicinity)", 
"Birmingham (and Vicinity)", 
"Birmingham (and vicinity), England, United Kingdom", 
"", 
now());

SELECT * 
FROM parentregionlist
WHERE MATCH(regionnamelong) 
AGAINST ('Birm' IN BOOLEAN MODE);

Any ideas?

P.S. In the real table I have 200k+ rows. I know the search won't work with just one row, it's just an example.

4

1 回答 1

0

使用当前查询,您正在寻找一个完整的单词匹配。因此,例如要插入上面显示的行,您需要执行以下操作:

SELECT * 
FROM parentregionlist
WHERE MATCH(regionnamelong) 
AGAINST ('Birmingham (and vicinity), England, United Kingdom' IN BOOLEAN MODE);

但是,如果您想搜索以“Birm”开头的所有结果,则需要添加“*”修饰符:

SELECT * 
FROM parentregionlist
WHERE MATCH(regionnamelong) 
AGAINST ('Birm*' IN BOOLEAN MODE);

或者,您也可以使用 LIKE:

SELECT * 
FROM parentregionlist
WHERE regionnamelong LIKE 'Birm%';

MySQL 文档提供了很好的 MATCH 示例以供使用: http ://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html

于 2013-08-13T14:40:59.643 回答