开发者

searching partial words with doctrine

I am trying to perform fulltext search with codeigniter and doctrine. My problem is that Doctrine perform t开发者_C百科he search only on wholes words.

For exemple, il I'am searching "mountain", I get every entry with the word mountain. But If I'am searching "mount", I get nothing.


I had the same problem with Symfony 1.4 and Doctrine 1.2 with the Searchable behaviour and came across this question. I then found you can add wildcards (? or *) to the search term which applies to the words. In your case "mount*" would match mountain. In my case I applied this to each search term and hid it from the user.

$results = $table->search('*'.$search_string.'*');

Hope this helps someone!

-- edit --

Posted a little hastily above... This works great for single word queries, but fails again on multiple partial words. Something like this should work better:

$actual_search_string = '*'.implode('* *', explode(' ', $search_string)).'*';
$results = $table->search($actual_search_string);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜