It's very easy to search with MYSQL LIKE searches.
Article::where('title', 'like', '%first%');
But, what would be the best way to use MYSQL Natural Language Full-Text Search?
SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('first');
Anybody that has tried to do this in Laravel 4 with Eloquent model?
Would be nice to have something like
$articles = Article::match('title|body')->against('word1|word2');
or
$articles = Article::matchAgainst('title|body','word1|word2');
Full text search is pretty vendor specific and not something that is currently supported by Laravel. You would need to run a raw query. Also, let's try to keep the Github Issue posting for actual "issues" or bugs. If you have a question a better place to ask would be the forums.
ok will do
try this
Article::whereRaw('MATCH (title, content) AGAINST (?)' , array($search))
Any reason why
whereRaw('MATCH (title, content) AGAINST (?)' , array($search))
where
$search = 'searchterm*'
doesn't yield a wildcard response? As if the "*" wasn't being passed into the query?
While in theory
whereRaw('MATCH (title, content) AGAINST (?)' , array($search))
will work, I found that binding failed when used in AGAINST.
I used it without binding like so
whereRaw("MATCH (title, content) AGAINST ('$search1')")
however this leaves you open to SQL injection, so you would need to sanitize your variable $search1 first.
Most helpful comment
try this
Article::whereRaw('MATCH (title, content) AGAINST (?)' , array($search))