[英]MySQL fulltext search over multiple columns does not deliver the expected results
我有一個名為“上載”的表格。 這些列是ID,日期,last_update,描述,標簽。 我添加了全文索引“ description_tags”,其中包括列說明和標簽。 表格式為MyISAM。 如果這可能是問題,我正在使用USBWebserver。
現在,我嘗試選擇其中具有提供的GET變量的上載。
MATCH (description,tags) AGAINST ("'.urldecode($_GET['tags']).'")
但是結果的問題是:搜索“ lorem”時沒有結果,但是在查詢中添加IN BOOLEAN MODE時卻沒有結果。 “ Lorem”實際上位於描述列中。 在標簽列中搜索關鍵字沒有這個問題。 當我在描述表中搜索“ moree”時,甚至更有趣/煩惱,無論是否使用布爾模式,我都會得到結果...
這里有什么問題? 我沒看到
更新資料
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';
您的測試數據可能不完整。 請注意以下文檔 :
出現在50%或更多行中的單詞被認為是通用的,並且不匹配。
但是BOOLEAN MODE搜索的不同之處在於:
他們不使用50%閾值。
我猜“ 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.