Framework: Natural Language Full-Text Searches MATCH (title,body) AGAINST ('word')

Created on 30 Jan 2013  路  5Comments  路  Source: laravel/framework

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');

Most helpful comment

try this

Article::whereRaw('MATCH (title, content) AGAINST (?)' , array($search))

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Anahkiasen picture Anahkiasen  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

JamborJan picture JamborJan  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

felixsanz picture felixsanz  路  3Comments