On my site now, I have a ‘simple’ search form, where you can search for books. Not only for a title, or description (same table), but also to the related tables (Author, Publisher, …)
Most of the visiters are searching for ‘Book + Title’ and there comes the problem.
What I do is using the searchterm and adding in front and back a ‘%’, and 99% of the visiters don’t get any result.
In my search on Google a found a solution that was related with Fulltext search. Is Yii Framework supporting this?
In attachment I’ve added my search
$condition[] = '(title LIKE :string OR price LIKE :string OR ISBN LIKE :string OR description_user LIKE :string)';
$condition[] = 'is_sold = :is_sold';
$condition[] = 'is_deleted = :is_deleted';
$params[':is_sold'] = 0;
$params[':is_deleted'] = 0;
$criteria = new CDbCriteria;
$criteria->condition = implode(' AND ', $condition);
$criteria->params = $params;
$criteria->with = array('authorlink', 'user', 'publisher');
$criteria->addSearchCondition('authorlink.name', '%' . $searchstring->search_string . '%', false, 'OR');
$criteria->addSearchCondition('publisher.name', '%' . $searchstring->search_string . '%', false, 'OR');
$criteria->addSearchCondition('user.name_first', '%' . $searchstring->search_string . '%', false, 'OR');
$criteria->addSearchCondition('user.name_last', '%' . $searchstring->search_string . '%', false, 'OR');
$items = Item::model()->findAll($criteria);