I am using FullText
Searching in MySQL
my database table engine type is MyISAM
.
Now problem is that i want to allow use to search record if they have entered three words.
But problem is that FullText
not allowing me to search record less than 4 character.
I know i can change
ft_min_word_len
to make it work but when i will upload it i need to change it on server and i am using shared host so its hard.
So how can i make it work in mysql Query.
I think when word are less than 4 character use LIKE
clause and when its greter than 4 use fulltext
, Is this right way?
Code
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";
I have used above code.
is it possible to search three character ?
I also tried +str*
but still now working.