[英]MySQL fulltext search over multiple columns does not deliver the expected results
I have a table called 'uploads'. 我有一个名为“上载”的表格。 The columns are id, date, last_update, description, tags. 这些列是ID,日期,last_update,描述,标签。 And I added the fulltext index 'description_tags' which includes those both columns description and tags. 我添加了全文索引“ description_tags”,其中包括列说明和标签。 The table format is MyISAM. 表格式为MyISAM。 I am using USBWebserver if this could be the problem. 如果这可能是问题,我正在使用USBWebserver。
Now I try to select the uploads which have the provided GET variables in them. 现在,我尝试选择其中具有提供的GET变量的上载。
MATCH (description,tags) AGAINST ("'.urldecode($_GET['tags']).'")
But the problems with the results I have are: There is no result when i search for 'lorem', but there is one when I add IN BOOLEAN MODE to the query. 但是结果的问题是:搜索“ lorem”时没有结果,但是在查询中添加IN BOOLEAN MODE时却没有结果。 The 'Lorem' is actually in the description column. “ Lorem”实际上位于描述列中。 Searching keywords in the tags column don't have that problem. 在标签列中搜索关键字没有这个问题。 And even more interesting/annoying when I search for 'moree', which is also in the description table, I get results with and without the boolean mode... 当我在描述表中搜索“ moree”时,甚至更有趣/烦恼,无论是否使用布尔模式,我都会得到结果...
What is the problem here? 这里有什么问题? I don't see it. 我没看到
Update 更新资料
if ( $upload_display_sort == 'popular' )//sort by popularity
$query = //select 'u' (a new defined variable?)
'SELECT u.* '.
//from the following table
'FROM '.
//uploads table as variable u
'uploads u '.
//join the following table
'LEFT OUTER JOIN '.
//select the column upload_id, count all columns into variable 'num' ???
'(SELECT upload_id, COUNT(*) AS num '.
//from the favorites table as variable f
'FROM favorites f '.
//and group it by the upload_id in the favorites table
'GROUP BY upload_id) '.
//what does this do? combine rows where the u.id == f.upload_id ???
'f ON u.id = f.upload_id';
else $query = 'SELECT * FROM uploads';//select all from uploads
$query .= ' WHERE online_state = 1';//select all online uploads
//FILTER FAVORITES
if ($upload_display_sort == 'favorites' and !empty($favorites_ids))
$query .= ' AND id IN ('.implode(',', $favorites_ids).')';//returns 1,2,3,4,5
elseif ($upload_display_sort == 'favorites' and empty($favorites_ids))
$query .= ' AND id IN (0)';//no upload id is 0
//FILTER SEARCH
if ( isset($_GET['tags']) )
$query .= ' AND MATCH (description,tags) AGAINST ("'.urldecode($_GET['tags']).'" IN BOOLEAN MODE)';
//FILTER DATE
if ( isset($_GET['timeframe'] )
and ( $_GET['timeframe'] == '3days'
or $_GET['timeframe'] == '2weeks'
or $_GET['timeframe'] == '3months') )
{
$end_date = time();//current time in unix format
switch ( $_GET['timeframe'] )
{
case '3days': $start_date = strtotime('-3 days',$end_date); break;
case '2weeks': $start_date = strtotime('-2 weeks',$end_date); break;
case '3months': $start_date = strtotime('-3 months',$end_date); break;
default: $start_date = strtotime(''); break;//1970-01-01 01:00:00
}
$end_date = date("Y-m-d H:i:s", $end_date);//current time in mysql format
$start_date = date("Y-m-d H:i:s", $start_date);//end time in mysql format
$query .= ' AND last_update BETWEEN "'.$start_date.'" AND "'.$end_date.'"';
}
//ORDER
$query .= ' ORDER BY';
if ( $upload_display_sort == 'popular' )//sort by popularity
$query .= ' f.num DESC,';
$query .= ' last_update DESC, id DESC';
Your test data may be incomplete. 您的测试数据可能不完整。 Note the following from the docs : 请注意以下文档 :
Words that are present in 50% or more of the rows are considered common and do not match. 出现在50%或更多行中的单词被认为是通用的,并且不匹配。
Yet BOOLEAN MODE searches differ in that: 但是BOOLEAN MODE搜索的不同之处在于:
They do not use the 50% threshold. 他们不使用50%阈值。
I'm guessing "lorem" appears in 50% or more of the rows. 我猜“ lorem”出现在50%或更多的行中。
BOOLEAN MODE
full text searches don't automatically sort by decreasing relevance. BOOLEAN MODE
全文搜索不会通过降低相关性来自动排序。 You'll need to sort them yourself like this: 您需要像这样对它们自己进行排序:
SELECT *, MATCH (description,tags) AGAINST ("lorem") AS relevance
FROM uploads
WHERE MATCH (description,tags) AGAINST ("lorem" IN BOOLEAN MODE)
ORDER BY relevance DESC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.