How to search on the server using Laravel Scout with Algolia Scout Extend.
Searchable class using thesearch method.The search method accepts a single string to search in yourSearchable class index:$articles = Article::search('Star Trek')->get();where method to filter your search results.With Scout Extended, this method shares the same API as the Laravel Query Builder,so you can filter results either with a comparison or a numerical range:$articles = Article::search('Star Trek')->where('views','>',100)->get();$articles = Article::search('Star Trek')->where('created_at','>=',now()->subDays(7))->get();$articles = Article::search('Star Trek')->where('views',100)->get();// views = 100where method supports the following operators:<,<=,=,!=,>=,>.whereBetween method filters results for which the provided field falls between the given range:$products = Products::search('Star Trek') ->whereBetween('price', [100,200]) ->get();whereIn method filters results for which the value of the provided field is part of the given array:$products = Products::search('Star Trek') ->whereIn('id', [1,2]) ->get();aroundLatLng method adds a geolocation parameter to the search request.You can define a point with its coordinates.This method is syntactic sugar, and you can use the methodwith to specify more location details such asaroundLatLng andaroundRadius.$articles = Article::search('query') ->aroundLatLng(48.8588536,2.3125377) ->get();with method gives you complete access to customize searchAPI parameters.$articles = Article::search('Star Trek') ->with([ 'hitsPerPage' => 30, 'filters' => 'attribute:value', 'typoTolerance' => false, ])->get();count method returns the number of hits the query matches:$count = Article::search('Star Trek')->count();scoutMetadata method to retrieve an array with more information about any hit.The key_highlightResult holds all the highlighted attributes.By default, Algolia highlights all the searchable attributes.You can change this with thearoundLatLng parameter.$metadata = Article::search('Star Trek')->get()->first()->scoutMetadata();$highlightResult = $metadata['_highlightResult'];getRankingInfo search parameter totrue, thegetRankingInfo holds detailed ranking information.It lets you see whichranking criteria played a role in selecting each model:$metadata = Article::search('Star Trek')->get()->first()->scoutMetadata();$rankingInfo = $metadata['_rankingInfo'];Was this page helpful?