Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kekekiw123's avatar

Looking for a search engine for my Laravel app

I am building a used cars application with Laravel.

Now I need to implement some sort of filter / search engine in order to search for cars.

MySql fulltext search doesnt seem to work fast? - On a big DB

So now I wonder if anyone here has used:

  • Elasticsearch
  • Solr
  • Sphinx

If so, could you please share your pros / cons.

Also worth saying, I have never worked with any search engine, so I would like to find one thats easy as possible but still fast with fulltext search. -Or at least a tutorial on how to implement it.

Thanks in advance,

0 likes
18 replies
freekmurze's avatar
Level 13

Of the engines you mention I've only worked with Elasticsearch and I'm quite happy with it.

To get started you could take a look at talk by Ben Corlett at Laracon 2014: https://murze.be/2015/01/using-elasticsearch-in-laravel/

Working with Elasticsearch in Laravel is easy with this package: https://github.com/freekmurze/searchindex

If you want to install elasticsearch on your dev machine or server you could follow these instructions on the Vaprobash repo: https://github.com/fideloper/Vaprobash/blob/master/scripts/elasticsearch.sh

11 likes
kekekiw123's avatar

@freekmurze excellent links, thanks!

Worth saying, I only have one row in my table which is used for fulltext search. My row "title" - varchar(45) then I have 5 more rows which are (int) and those are easy to filter out with a simple where(). I never used any search engine, so will Elasticsearch be a bit overkill for my needs?

Thanks

freekmurze's avatar

It depends. If sorting results by relevancy is important to you, use a search engine.

3 likes
christopher's avatar

I really dont understand these search engines .. For example: If i store products the products are all stored in the search engine and not in the mysql database is this correct ?

And if i do a search i search in the "index" of the search engine and the result im getting is in JSON ?

gradientps's avatar

public static function search($term) { YourModel::where('title', 'LIKE', '%'.$term.'%')->get(); }

kekekiw123's avatar

@freekmurze Have you tried the ES package using Laravel 5?

It says "This is an opinionated Laravel 4 | 5 package" .. So I guess it should work, but you never know :)

freekmurze's avatar

It should work. I'll check it again shortly after the stable version of L5 is available.

kekekiw123's avatar

@freekmurze Do you have any sample code with Laravel using ES.

The samples from the Laracon intro and github doesn't look the same, and are not that clear to me as a noob. @freekmurze My idea is to still keep MySQL since I only need to search one table with ES.

I would look to find some code that shows on how to eg: Insert a model into MySQL and then insert that same model into ES.

And also some code sample on how to perform a search on that model.

Is there support for inner join in ES as well?

Thanks in advance,

pixelpeter's avatar

Just implemented ElasticSearch in my Laravel 5 application using https://github.com/freekmurze/searchindex and everything is working fine.

The documentation provided has everything you need to get started quickly.

I'm using model events to update the ES index whenever I create or update my data sets.

Now I just need to figure out how to do a full-text search and substring matching ... ... as already said: the php side is fine ;)

olimorris's avatar

@pixelpeter model events sounds like a solid idea and glad to know the package was super simple to use right out of the box.

In the future I'd be keen to add another server box to my stack and have Elasticsearch running solely from that. It looks like I could just use the IP of that box in the freekmurze package and all pushes to ES would be handled on that server. If anyone has experience of this and can confirm would be great.

Please or to participate in this conversation.