Is there anything similar to full text searches in laravel?

1

I intend to show any row that contains at least one of the searched words, and in case of coinciding in several, that orders it from higher to lower number of coincidences.

I have found information about the Like wildcard with laravel, but I know that when using the Like wildcard the results returned by the search engine can be very high and totally irrelevant. that's why I'm looking for something similar to full Text- I have also found something of Angolia. but I do not want to use angolia

since, as I mentioned, I intend to search for any row that contains at least one of the searched words, and in case of coinciding in several, that orders it from higher to lower number of coincidences.

That's how I used to do it

ALTER TABLE coches ADD FULLTEXT (nombre, descripcion);

.

SQL="Select nombre, descripcion From coches Where Match(nombre, descripcion) AGAINST ('criterio');"

but in laravel how is it possible with Eloquent?

    
asked by Alex Burke Cooper 01.04.2018 в 06:44
source

1 answer

2

Is there something similar to fullText searches in laravel? Answer: yes (use direct and raw SQL) and no (not supported).

How is it possible with eloquent?:

1 with an extension (for example this one)

link

2 bareback (raw queries) as you come doing it.

$query->whereRaw("Select nombre, descripcion From coches Where 
Match(nombre, descripcion) AGAINST ('criterio');";

the alter can be put in a migration (also raw sql)

DB::statement('ALTER TABLE coches ADD FULLTEXT (nombre, descripcion);";

To "laravelize" the code and reuse it (without using extensions) I recommend the following tutorial:

link

Note: why does Laravel not support fulltext search native?

Taylor Otwell, the creator of Laravel, wants to keep Eloquent as platform-independent as possible. And since Full Text Search is specific to MySQL, it was not included. In his own words: "Full text search is pretty specific and not something that is currently supported by Laravel."

link

free translation:

Taylor Otwell, the creator of Laravel, wants to keep Eloquent as independent of the platforms as possible. And since Full Text Search is MySQL specific, it was not included. In his own words: "Full text search is quite specific to a vendor / supplier / manufacturer and is not something that is currently supported by Laravel."
    
answered by 01.04.2018 / 06:50
source