- Notifications
You must be signed in to change notification settings - Fork8
DEPRECATED: Use of this repository is deprecated. Please use Scout Extended -https://github.com/algolia/scout-extended instead.
License
algolia/laravel-scout-algolia-macros
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
DEPRECATED: Use of this repository is deprecated. Please use Scout Extended -https://github.com/algolia/scout-extended instead.
A collection of useful macros to extend Laravel Scout capabilities when using theAlgolia engine.
This package aims to provide a set of macros to take advantage of theAlgolia-specific feature.
Pull the package using composer
composer require algolia/laravel-scout-algolia-macrosNext, you should add theAlgolia\ScoutMacros\ServiceProvider to theprovidersarray of yourconfig/app.php configuration file:
Algolia\ScoutMacros\ServiceProvider::class
The count method will return the number of results after the request to Algolia.
The point is to avoid pull data from the database and building the collection.
$nbHits = Model::search('query')->count();
Thehydrate method is similar to the standard get() method, except it hydrates the models from your Algolia index.
By default, Scout will use the IDs of the results from Algolia and pull the data from the local database to create the collection.
Hence,hydrate will be much faster thanget.
Note: By using this method you must be sure that you are correctly keeping your algolia index in sync with your databaseto avoid populating stale data.
By default, this method will add all attributes from Algolia's record to your model. If you want to remove sensitive or irrelevant data from your model, you have two options.
You can set a list of retrievable attributes in your Algolia dashboard. In this case, Algolia will only return these attributes while still searching everysearchableAttributes.
You may as well use the laravel$guarded attributes of your model class. For instance, if you don't want to see the_h attribute in your collection, you will have the following.
namespaceApp;useIlluminate\Database\Eloquent\Model;useLaravel\Scout\Searchable;class Peopleextends Model{use Searchable;protected$guarded = ['_highlightResult'];}
Thewith method gives you complete access to the Algolia options parameter. This allows youto customise the search parameters exactly the same as you would using the algolia php library directly.
$result = Model::search('')->with(['hitsPerPage' =>30])->get();
$filters = ['averge_ratings >= 3','total_reviews >= 1'];$filterString =implode(' AND',$filters);$params = ['aroundLatLng' =>$lat.','.$lon,'hitsPerPage' =>30,'page' =>0,'aroundRadius' =>30000,//30km'aroundPrecision' =>200,//200 Meters'getRankingInfo' =>true,//return ranking information in results'filters' =>$filterString// add filters ];$result = Model::search('')->with($params)->get();
ThearoundLatLng method will addgeolocation parameter to the search request. Youcan define a point with its coordinate.
Note that this method is pure syntactic sugar, you can usewith to specify more location details (like radius for instance)
// Models around Paris latitude and longitudeModel::search('query')->aroundLatLng(48.8588536,2.3125377)->get();
Where clauses can also be added
Model::search('query') ->aroundLatLng(48.8588536,2.3125377) ->where('something_id',1) ->get();
Feel free to open an issue to request a macro.
Open any pull request you want, so we can talk about it and improve the package. 🎉
About
DEPRECATED: Use of this repository is deprecated. Please use Scout Extended -https://github.com/algolia/scout-extended instead.
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors7
Uh oh!
There was an error while loading.Please reload this page.