我正在使用FullText
在MySQL
中搜索我的數據庫表引擎類型爲MyISAM
。三個字符搜索不起作用
現在的問題是,我想允許使用搜索記錄,如果他們已經輸入三個單詞。
但問題是,FullText
不允許我搜索少於4個字符的記錄。
我知道我可以改變
ft_min_word_len
,使其工作,但是當我將它上傳我需要改變它在服務器上,我使用共享主機,以便其難。
那麼我怎麼能讓它在mysql查詢中工作。
我認爲當字少於4個字符使用LIKE
子句和當它比4使用fulltext
,這是正確的方式嗎?
代碼
App::import('Sanitize');
if(strlen($this->params['named']['q']) <= 4)
{
$lessWord = "+".$this->params['named']['q'];
}
else
{
$lessWord = $this->params['named']['q'];
}
$escapedQuery = str_replace(" ","* ",Sanitize::escape($lessWord)).'*';
array_push($this->paginate['conditions'],"MATCH(ServiceRequest.title, ServiceRequest.description) AGAINST ('".$escapedQuery."' IN BOOLEAN MODE)");
$this->paginate['fields'] = array
(
'*',
"MATCH(ServiceRequest.title, ServiceRequest.description) AGAINST ('".$escapedQuery."' IN BOOLEAN MODE) AS score"
);
$this->paginate['order'] = "score DESC";
我已經在上面的代碼中使用。
是否可以搜索三個字符?
我也試過+str*
,但現在仍在工作。
@Jocelyn正如我所說我不想改變這個變量......請在閱讀它之前不要關閉它...... –
@Jocelyn我已經突出顯示了對你的迴應關閉有問題的投票 –
@DipeshParmar +1爲好問題,等待正確的答案。 –