简体   繁体   English

MySQL全文匹配除精确匹配之外的所有内容?

[英]MySQL Fulltext matches everything but the exact match?

I am facing a weird situation where my full text search query seems to match everything except the exact match... 我面临一种奇怪的情况,即我的全文搜索查询似乎与除完全匹配之外的所有内容都匹配...

I mean if the input is: 我的意思是,如果输入是:

Empire Total War 帝国全面战争

it will match it as: 它将匹配为:

Empire Total War Limited Edition 帝国全面战争限量版
...altough there is a record in the database that says exactely: Empire Total War ...虽然数据库中有一条记录准确地说: 帝国全面战争

This is my query: 这是我的查询:

     $query_GID = "SELECT game, gameID, 
    MATCH (game) AGAINST ('$game_title') AS score 
FROM gkn_catalog_match WHERE MATCH (game) AGAINST
  ('$game_title');";
$result_GID = $dbc->query($query_GID);
$row_GID = mysqli_fetch_array($result_GID,MYSQLI_ASSOC);

For debugging purposes I went ahead and wrote this code to output all the matching alternatives in the returned array, however the exact match is not within it... 出于调试目的,我继续编写了此代码,以在返回的数组中输出所有匹配的替代项,但是其中不包含确切的匹配项...

$GID = $row_GID['gameID'];
$GName = $row_GID['game'];
$Gscore = $row_GID['score'];
$max_score = 0;
$data = array();
while($row_GID = mysqli_fetch_assoc($result_GID)) {
if($row_GID['score'] > $max_score){ $max_score = $row_GID['score']; } //because we are ordering by score we can assume on the first run this wil be the max score.
echo "<br><b>Alternatives: " .$row_GID['game']."".@number_format(($row_GID['score']/$max_score)*100,0)."%</b>\n";

}

My question is: Why am I not getting the desired/exact match even though the input string AND the record in my database are identical? 我的问题是:为什么即使输入字符串和数据库中的记录相同,我也无法获得想要的/精确的匹配?
And even if I output the array it seems like the exact match is not even pulled from the database as its nowhere to be found in the array. 而且即使我输出了数组,似乎也没有从数据库中提取出完全匹配项,因为在数组中找不到它。

Edit: 编辑:

Example Situation Records in Database: 数据库中的情况记录示例:

Crysis 孤岛危机
Crysis 2 孤岛危机2
Crysis 2 Maximum Edition 孤岛危机2最高版
Crysis 3 孤岛危机3
Crysis 3 Hunter Edition 孤岛危机3猎人版

Search String (Input): Crysis 3 搜索字符串(输入):孤岛危机3
Match returned by query: Crysis 3 Hunter Edition 查询返回的匹配项:《孤岛危机3猎人版》

Crysis 3 is not being matched instead another record like Crysis 3 Hunter Edition is matched, which is... unexpected as I want it to match Crysis 3. Crysis 3未匹配,而是匹配了Crysis 3 Hunter Edition之类的另一条记录,这是意外的,因为我希望它与Crysis 3匹配。

When I output the $row array of this query I can see that Crysis 3 is not included: 当我输出此查询的$ row数组时,我可以看到不包括孤岛危机3:
Alternatives: Crysis 3 Hunter Edition 100% 替代方案:孤岛危机3猎人版100%
Alternatives: Crysis 2 Maximum Edition 82% 替代方案:孤岛危机2最高版82%
Alternatives: Crysis 70% 替代方案:孤岛危机70%
Alternatives: Far Cry 3 Deluxe Edition 32% 替代方案:孤岛惊魂3豪华版32%
Alternatives: Far Cry 2 Fortune Edition 32% 替代方案:孤岛惊魂2财富版32%
Alternatives: SimCity 4 Deluxe Edition 31% 替代方案:SimCity 4 Deluxe Edition 31%
Alternatives: SimCity Limited Edition 31% 替代方案:SimCity限量版31%
Alternatives: Battlefield 3 Premium Edition 31% 替代方案:《战地风云3》高级版31%
Alternatives: Battlefield 3 Limited Edition 31% 替代方案:《战地风云3》限量版31%
Alternatives: Civilization 5 Gold Edition 31% 替代方案:文明5黄金版31%

Edit 2: 编辑2:

Entering the query manually returns the desired result. 手动输入查询将返回所需的结果。
So the query seems to work, however I seem to lost the first entry of the returned array... 因此查询似乎有效,但是我似乎丢失了返回数组的第一个条目...

I solved my problem by moving the array allocation outside of the while loop. 我通过将数组分配移到while循环outside解决了我的问题。
Now the Fulltext query matches the game titles up to 99.9% if they exist within the database. 现在,如果数据库中存在游戏标题,则全文查询最多可匹配99.9%的游戏标题。

If not, it goes kinda crazy. 如果没有,那就有点疯狂了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM