Reputation: 1918
I need to write a fluent query for full text search in Laravel 3.0. The search query goes like this
SELECT * FROM posts WHERE MATCH (tags) AGAINST ('Lorem Ipsum Dolor Sit Amet');
I had been using Raw query to perform this operation but the results from a raw query could not be paginated. Can anyone tell me the right way to write a fluent query for this query?
Upvotes: 2
Views: 1564
Reputation: 11749
Maybe try this....??
public static function find_tags($searchtags, $take = 20)
{
$results = Posts::raw_where("match (`tags`) against (?)", array($searchtags))
->take($take)
->get();
return $results;
}
Or just...
$searchtags = "Lorem ipsum blah";
$results = Posts::raw_where("match (`tags`) against (?)", array($searchtags))
->paginate(10);
Im just pulling this out of the air though, can't test right now....not at my server...
Upvotes: 2
Reputation: 5005
Actually you don't need to perform a raw select statement, all that would have to be written in a raw query is the where() statement. So why don't you try something like this, I'm currently having some issues with my local server so I can't test this by myself but this should work.
// If you're using laravel models
Posts::where_raw(sprintf("MATCH (tags) AGAINST ('%s')", $search))->paginate(10);
where_raw is one of laravel's undocumented functions :D, also keep in mind when using raw queries escaping is not performed so be careful.
Upvotes: 0