PHPackages                             kennedytedesco/meilisearch-search-filter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. kennedytedesco/meilisearch-search-filter

ActiveLibrary[API Development](/categories/api)

kennedytedesco/meilisearch-search-filter
========================================

A fluent and intuitive way to construct filters for Meilisearch queries.

v1.0(2y ago)45.7k↓50%MITPHPPHP ^8.1

Since Aug 30Pushed 2y agoCompare

[ Source](https://github.com/KennedyTedesco/meilisearch-search-filter)[ Packagist](https://packagist.org/packages/kennedytedesco/meilisearch-search-filter)[ RSS](/packages/kennedytedesco-meilisearch-search-filter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Meilisearch Search Filter
=========================

[](#meilisearch-search-filter)

[![Build Status](https://github.com/KennedyTedesco/meilisearch-search-filter/actions/workflows/tests.yml/badge.svg)](https://github.com/KennedyTedesco/meilisearch-search-filter/actions/workflows/tests.yml)[![PHPStan](https://camo.githubusercontent.com/83dd3d35cebed0eab9ee97ff1a5849c1344cda6a8ee9cac2cda20f5aa55b67bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c6174)](https://img.shields.io/badge/PHPStan-level%209-brightgreen.svg?style=flat)[![License](https://camo.githubusercontent.com/3fb3d92f5a1110d7f8217a896b3e9a0d0858421dfc9c6318adea01d580008b47/68747470733a2f2f706f7365722e707567782e6f72672f6b656e6e6564797465646573636f2f6d65696c697365617263682d7365617263682d66696c7465722f6c6963656e7365)](//packagist.org/packages/kennedytedesco/meilisearch-search-filter)

This zero-dependency library provides a fluent and intuitive way to construct filters for Meilisearch queries. It simplifies the process of building filters by offering a chainable API.

Installation
------------

[](#installation)

**Minimum requirements:** PHP 8.1 or higher.

To use this library in your project, you can install it using Composer:

```
composer require kennedytedesco/meilisearch-search-filter "^1.0"
```

Usage
-----

[](#usage)

You can learn how Meilisearch filters work by reading the [official documentation](https://www.meilisearch.com/docs/learn/fine_tuning_results/filtering).

You should also check out the [Meilisearch PHP SDK](https://github.com/meilisearch/meilisearch-php).

Here are some examples that demonstrate how to build filters using this library:

```
use Meilisearch\Client;
use KennedyTedesco\Meilisearch\SearchFilter\SearchFilter;

$client = new Client('http://127.0.0.1:7700', 'masterKey');

$filter = SearchFilter::new()
    ->where(function (SearchFilter $filter) {
        $filter->whereGreaterThan('rating.critics', 80)
            ->whereGreaterThanOrEqual('rating.users', 70);
    })
    ->whereIn('genres', ['Horror', 'Thriller']);

$index = $client->index('movies');

$results = $index->search('wonder', [
    // (rating.critics > 80 AND rating.users >= 70) AND genres IN ["Horror", "Thriller"]
    'filter' => $filter->build(),
]);
```

You can also use alias methods when constructing filters:

```
use KennedyTedesco\Meilisearch\SearchFilter\SearchFilter;

$filter = SearchFilter::new()
    ->where(function (SearchFilter $filter) {
        $filter->whereGt('rating.critics', 80)
            ->whereGte('rating.users', 70);
    })
    ->orWhereIn('genres', ['Horror', 'Thriller']);

echo $filter->build();

// Output: (rating.critics > 80 AND rating.users >= 70) OR genres IN ["Horror", "Thriller"]
```

Alternatively, you can use the `where(...)` method and pass the operator as the second argument:

```
use KennedyTedesco\Meilisearch\SearchFilter\SearchFilter;

$filter = SearchFilter::new()
    ->where(function (SearchFilter $filter) {
        $filter->where('rating.critics', '>', 80)
            ->where('rating.users', '>=', 70);
    })
    ->orWhereIn('genres', ['Horror', 'Thriller']);

echo $filter->build();

// Output: (rating.critics > 80 AND rating.users >= 70) OR genres IN ["Horror", "Thriller"]
```

#### Using Between

[](#using-between)

The `TO` operator is equivalent to `>=` AND `whereBetween('rating.critics', 80, 90);

echo $filter->build();

// Output: rating.critics 80 TO 90
```

If you want your results to only include "comedy" and "horror" movies released after March 1995, it's mandatory to group the `OR` conditions:

```
use KennedyTedesco\Meilisearch\SearchFilter\SearchFilter;

$filter = SearchFilter::new()
    ->where(function (SearchFilter $filter) {
        $filter->where('genres', 'horror')
            ->orWhere('genres', 'comedy');
    })
    ->where('release_date', '>', '795484800');

echo $filter->build();

// Output: (genres = "horror" OR genres = "comedy") AND release_date > 795484800
```

So, when you provide a closure to the `where()` or `orWhere()` methods, a fresh `SearchFilter` instance is passed to the closure as the first argument. This lets you craft nested filters within parentheses.

#### Using `when()`

[](#using-when)

The `when()` method allows you to conditionally add filters to the query. For example:

```
use KennedyTedesco\Meilisearch\SearchFilter\SearchFilter;

$filter = SearchFilter::new()
    ->when($request->filled('type'), function (SearchFilter $filter) use($request) {
        $filter->where('type', $request->get('type'));
    })
    ->where('release_date', '>', '795484800');
```

### All available filter methods

[](#all-available-filter-methods)

MethodDescription`where(...$args)`Adds a filter condition using the `AND` logical operator.`whereGreaterThan(...$args)`Adds a greater than comparison filter condition.`whereGt(...$args)`Alias for `whereGreaterThan`.`whereGreaterThanOrEqual(...$args)`Adds a greater than or equal to comparison filter condition.`whereGte(...$args)`Alias for `whereGreaterThanOrEqual`.`whereLessThan(...$args)`Adds a less than comparison filter condition.`whereLt(...$args)`Alias for `whereLessThan`.`whereLessThanOrEqual(...$args)`Adds a less than or equal to comparison filter condition.`whereLte(...$args)`Alias for `whereLessThanOrEqual`.`whereNot(...$args)`Adds a not equal comparison filter condition.`whereIn(...$args)`Adds a filter to check if the attribute value is in a given array of values.`whereNotIn(...$args)`Adds a filter to check if the attribute value is not in a given array of values.`whereExists(...$args)`Adds a filter to check if the attribute value exists.`whereNotExists(...$args)`Adds a filter to check if the attribute value does not exist.`orWhere(...$args)`Adds a filter condition using the `OR` logical operator.`orWhereGreaterThan(...$args)`Adds a greater than comparison filter condition using `OR` logical operator.`orWhereGt(...$args)`Alias for `orWhereGreaterThan`.`orWhereGreaterThanOrEqual(...$args)`Adds a greater than or equal to comparison filter condition using `OR` logical operator.`orWhereGte(...$args)`Alias for `orWhereGreaterThanOrEqual`.`orWhereLessThan(...$args)`Adds a less than comparison filter condition using `OR` logical operator.`orWhereLt(...$args)`Alias for `orWhereLessThan`.`orWhereLessThanOrEqual(...$args)`Adds a less than or equal to comparison filter condition using `OR` logical operator.`orWhereLte(...$args)`Alias for `orWhereLessThanOrEqual`.`orWhereNot(...$args)`Adds a not equal comparison filter condition using `OR` logical operator.`orWhereIn(...$args)`Adds a filter to check if the attribute value is in a given array of values using `OR` logical operator.`orWhereNotIn(...$args)`Adds a filter to check if the attribute value is not in a given array of values using `OR` logical operator.`orWhereExists(...$args)`Adds a filter to check if the attribute value exists using `OR` logical operator.`orWhereNotExists(...$args)`Adds a filter to check if the attribute value does not exist using `OR` logical operator.`whereBetween(...$args)`Adds a filter to check if the attribute value is between two values.`whereNotBetween(...$args)`Adds a filter to check if the attribute value is not between two values.`orWhereBetween(...$args)`Adds a filter to check if the attribute value is between two values using `OR` logical operator.`orWhereNotBetween(...$args)`Adds a filter to check if the attribute value is not between two values using `OR` logical operator.`whereEmpty(...$args)`Adds a filter to check if the attribute value is empty.`whereNotEmpty(...$args)`Adds a filter to check if the attribute value is not empty.`orWhereEmpty(...$args)`Adds a filter to check if the attribute value is empty using `OR` logical operator.`orWhereNotEmpty(...$args)`Adds a filter to check if the attribute value is not empty using `OR` logical operator.`whereNull(...$args)`Adds a filter to check if the attribute value is null.`whereNotNull(...$args)`Adds a filter to check if the attribute value is not null.`orWhereNull(...$args)`Adds a filter to check if the attribute value is null using `OR` logical operator.`orWhereNotNull(...$args)`Adds a filter to check if the attribute value is not null using `OR` logical operator.Contributing
------------

[](#contributing)

If you'd like to contribute to this project, feel free to submit pull requests or open issues on the GitHub repository.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

987d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc66b6764f3a4bd0c805219543b04dcd9d43f801f066735ed5a80658fdb33420?d=identicon)[KennedyTedesco](/maintainers/KennedyTedesco)

---

Top Contributors

[![KennedyTedesco](https://avatars.githubusercontent.com/u/999232?v=4)](https://github.com/KennedyTedesco "KennedyTedesco (10 commits)")

---

Tags

phpapiclientsearchinstantmeilisearchfilterfiltersqueries

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kennedytedesco-meilisearch-search-filter/health.svg)

```
[![Health](https://phpackages.com/badges/kennedytedesco-meilisearch-search-filter/health.svg)](https://phpackages.com/packages/kennedytedesco-meilisearch-search-filter)
```

###  Alternatives

[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69333.0M114](/packages/algolia-algoliasearch-client-php)[meilisearch/search-bundle

Seamless integration of Meilisearch into your Symfony project.

154356.2k](/packages/meilisearch-search-bundle)[kunalvarma05/dropbox-php-sdk

Dropbox PHP API V2 SDK (Unofficial)

3633.0M18](/packages/kunalvarma05-dropbox-php-sdk)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
