Question

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.

Was it helpful?

Solution

ft_min_word is a setting of the MySQL server. In case of hosting server, you cannot therefore change it in the ini_set (which isfor PHP). The server is a seperate thing, and if your host has multiple users using the same server (which is standard on a shared server), they will use the same setting.

The same goes for a .htaccess setting: this can only change how apache will react (if allowed to change), not how the database server is configured.

The variable, described here in the manual is not a dynamic variable that can be set in runtime

So you can try :

Check the length of the search term, then, if it is less than allowed by ft_min_word, use LIKE('%searchterm%')

OTHER TIPS

change this line

if(strlen($this->params['named']['q']) <= 3)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top