Using Algolia in Laravel
Algolia is a hosted service that makes advanced searching very easy. It's well documented and lightning quick. You can see some impressive examples on their site. Artisans probably know that Jeffrey Way recently published a series on Algolia.
Earlier this year I made a package to easily work with a searchindex in Laravel. Basically it provides:
- an interface that makes your objects searchable
- some easy to use functions to put those objects into the search index
- a function to retrieve search results from the index
Using my package you just got to implement the Searchable
-interface on an object you want to index. That object can be an Eloquent model, but you really can use it on any class you like. Once the interface is implemented these methods can be used:
[code language="php"] //$product is an object that implements the Searchable interface
//adding or updating something to the index SearchIndex::upsertToIndex($product);
//removing something from the index SearchIndex::removeFromIndex($product);
SearchIndex::getResults('my favorite product');
To perform more advanced queries an array may be passed to the `getResults`-function. Read <a href="https://github.com/algolia/algoliasearch-client-php#search">the official Algolia documentation</a> to learn what's possible.
You'll find some more information on the package on GitHub:
<a href="https://github.com/spatie/searchindex">https://github.com/spatie/searchindex</a>
What are your thoughts on "Using Algolia in Laravel"?