Search code examples
sqllaravelfull-text-searchlaravel-3

How can I write a fluent query for full text search?


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?


Solution

  • 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...