我有一个名为“上传”的表。这些列是 id、日期、last_update、描述、标签。我添加了全文索引“description_tags”,其中包括描述列和标签列。表格式为MyISAM。如果这可能是问题所在,我正在使用 USBWebserver。
现在我尝试选择其中包含提供的 GET 变量的上传。
MATCH (description,tags) AGAINST ("'.urldecode($_GET['tags']).'")
但是我得到的结果的问题是:当我搜索“lorem”时没有结果,但当我在查询中添加 IN BOOLEAN MODE 时有一个结果。 “Lorem”实际上在描述栏中。在标签栏中搜索关键字就不存在这个问题。更有趣/更烦人的是,当我搜索“moree”(也在描述表中)时,我得到带有或不带有 bool 模式的结果......
这里有什么问题吗?我没看到。
更新
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';
最佳答案
您的测试数据可能不完整。请注意 docs 中的以下内容:
Words that are present in 50% or more of the rows are considered common and do not match.
然而BOOLEAN MODE searches不同之处在于:
They do not use the 50% threshold.
我猜测“lorem”出现在 50% 或更多的行中。
BOOLEAN MODE
全文搜索不会自动按相关性递减排序。您需要自己对它们进行排序,如下所示:
SELECT *, MATCH (description,tags) AGAINST ("lorem") AS relevance
FROM uploads
WHERE MATCH (description,tags) AGAINST ("lorem" IN BOOLEAN MODE)
ORDER BY relevance DESC
关于php - MySQL 多列全文搜索未提供预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22462252/