> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Server-side search

> How to search on the server using Laravel Scout with Algolia Scout Extend.

export const SearchRequest = () => <Tooltip tip="A search request is a single HTTP call to the Algolia Search API that can run one or more search operations. It can include multiple queries, for example, when querying several indices at once.">
    search request
  </Tooltip>;

export const SearchQuery = () => <Tooltip tip="The text users enter into a search box. In the Search API, this corresponds to the query parameter. A search query is often used with filters, facets, and other parameters, but these aren't part of the query text itself.">
    search query
  </Tooltip>;

You can search in a `Searchable` class using the `search` method.
The search method accepts a single string to search in your `Searchable` class index:

```php PHP icon=code theme={"system"}
$articles = Article::search('Star Trek')->get();
```

<Info>
  You can also search with [pagination](https://laravel.com/docs/scout#pagination),
  and work with [soft deleted models](https://laravel.com/docs/scout#soft-deleting).
  To learn more, see the
  [Laravel Scout documentation](https://laravel.com/docs/scout#searching).
</Info>

### Search with numerical filters

You can use the `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:

```php PHP icon=code theme={"system"}
$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 = 100
```

The `where` method supports the following operators: `<`, `<=`, `=`, `!=`, `>=`, `>`.

### Search with numerical range filters

The `whereBetween` method filters results for which the provided field falls between the given range:

```php PHP icon=code theme={"system"}
$products = Products::search('Star Trek')
    ->whereBetween('price', [100, 200])
    ->get();
```

### Search with multiple filter values

The `whereIn` method filters results for which the value of the provided field is part of the given array:

```php PHP icon=code theme={"system"}
$products = Products::search('Star Trek')
    ->whereIn('id', [1, 2])
    ->get();
```

### Search with locational filters

The `aroundLatLng` method adds a geolocation parameter to the <SearchRequest />.
You can define a point with its coordinates.
This method is syntactic sugar, and you can use the method [`with`](#search-with-custom-search-parameters) to specify more location details such as [`aroundLatLng`](/doc/api-reference/api-parameters/aroundLatLng) and [`aroundRadius`](/doc/api-reference/api-parameters/aroundRadius).

```php PHP icon=code theme={"system"}
$articles = Article::search('query')
    ->aroundLatLng(48.8588536, 2.3125377)
    ->get();
```

### Search with custom search parameters

The `with` method gives you complete access to customize search [API parameters](/doc/api-reference/search-api-parameters).

```php PHP icon=code theme={"system"}
$articles = Article::search('Star Trek')
    ->with([
        'hitsPerPage' => 30,
        'filters' => 'attribute:value',
        'typoTolerance' => false,
    ])->get();
```

### Retrieve the number of hits

The `count` method returns the number of hits the <SearchQuery /> matches:

```php PHP icon=code theme={"system"}
$count = Article::search('Star Trek')->count();
```

### Retrieve hit metadata

You can use the `scoutMetadata` method to retrieve an array with more information about any hit.

The key [`_highlightResult`](/doc/rest-api/search/search-single-index#response-hits-items-highlight-result) holds all the highlighted attributes.
By default, Algolia highlights all the searchable attributes.
You can change this with the [`aroundLatLng`](/doc/api-reference/api-parameters/aroundLatLng) parameter.

```php PHP icon=code theme={"system"}
$metadata = Article::search('Star Trek')->get()->first()->scoutMetadata();
$highlightResult = $metadata['_highlightResult'];
```

If you set the [`getRankingInfo`](/doc/api-reference/api-parameters/getRankingInfo) search parameter to `true`,
the `_rankingInfo` response field holds detailed ranking information.
It lets you see which [ranking criteria](/doc/guides/managing-results/relevance-overview/in-depth/ranking-criteria) played a role in selecting each model:

```php PHP icon=code theme={"system"}
$metadata = Article::search('Star Trek')->get()->first()->scoutMetadata();
$rankingInfo = $metadata['_rankingInfo'];
```
