PHPackages                             loupe/loupe - 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. [Search &amp; Filtering](/categories/search)
4. /
5. loupe/loupe

ActiveLibrary[Search &amp; Filtering](/categories/search)

loupe/loupe
===========

A full text search engine with tokenization, stemming, typo tolerance, filters and geo support based on only PHP and SQLite

0.13.11(1mo ago)497185.2k↓38.4%24[6 issues](https://github.com/loupe-php/loupe/issues)[4 PRs](https://github.com/loupe-php/loupe/pulls)9MITPHPPHP ^8.1CI passing

Since Aug 1Pushed 1mo ago11 watchersCompare

[ Source](https://github.com/loupe-php/loupe)[ Packagist](https://packagist.org/packages/loupe/loupe)[ GitHub Sponsors](https://github.com/Toflar)[ RSS](/packages/loupe-loupe/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (32)Versions (77)Used By (9)

 [![Loupe](./logo/logo.svg)](./logo/logo.svg)
 **An SQLite based, PHP-only fulltext search engine.**

> Read the documentation: [loupe-php.github.io/loupe](https://loupe-php.github.io/loupe/)

Loupe…

- only requires PHP and SQLite, you don't need anything else - no containers, no nothing
- is typo-tolerant (based on the State Set Index Algorithm and Damerau-Levenshtein)
- supports phrase search using `"` quotation marks
- supports negative keyword and phrase search using `-` as modifier
- supports filtering (and ordering) on any attribute with any SQL-inspired filter statement
- supports filtering (and ordering) on Geo distance
- supports search facets
- orders relevance based on a number of factors such as number of matching terms, typos, proximity, word counts and exactness
- auto-detects languages
- supports stemming
- is very easy to use
- is all-in-all just the easiest way to replace your good old SQL `LIKE %...%` queries with a way better search experience but without all the hassle of an additional service to manage. SQLite is everywhere and all it needs is your filesystem.

Introductory blog post
----------------------

[](#introductory-blog-post)

If this is your first encounter with Loupe, you might want to read the [blog post on Medium](https://medium.com/@yanick.witschi/loupe-a-search-engine-with-only-php-and-sqlite-1c0d83024a71) or [as Markdown file](./docs/blog_post.md) that should give you more information about the reasons and what you can do with it. Note that some implementation details (e.g. libraries used) referenced in this blog post are not up-to-date anymore.

Performance
-----------

[](#performance)

Performance depends on many factors but here are some ballpark numbers based on indexing the [~32k movies fixture](https://www.meilisearch.com/movies.json) provided by MeiliSearch.

- **Querying** for `Amakin Dkywalker` with typo tolerance and relevance ranking takes about **26 ms**
- **Indexing** will take around **60 seconds** (this varies greatly because it depends on how much content per document you want to index

Note that anything above 50k documents is probably not a use case for Loupe. You can run your own benchmarks using the scripts in the `bin/bench` folder: `index.php` for indexing and `search.php` for searching. Please, also read the [Performance](./docs/performance.md) chapter in the docs. You may report your own performance measurements and more details in the [respective discussion](https://github.com/loupe-php/loupe/discussions/17).

Acknowledgement
---------------

[](#acknowledgement)

If you are familiar with MeiliSearch, you will notice that the API is very much inspired by it. The reasons for this are simple:

1. First and foremost: I think, they did an amazing job of keeping configuration simple and understandable from a developer's perspective. Basic search tools shouldn't be complicated.
2. If Loupe shouldn't be enough for your use case anymore (you need advanced features, better performance etc.), switching to MeiliSearch instead should be a piece of cake.

I even took the liberty to copy some of their test data to feed Loupe for functional tests.

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

[](#installation)

1. Make sure you have `pdo_sqlite` available and your installed SQLite version is at least 3.35.0. This is when RETURNING functions have been added without which no bulk inserts are possible. For best performance it is of course better to run a more recent version to benefit from improvements within SQLite.
2. Run `composer require loupe/loupe`.

Usage
-----

[](#usage)

### Creating a client

[](#creating-a-client)

The first step is configuring and creating a client.

```
use Loupe\Loupe\Config\TypoTolerance;
use Loupe\Loupe\Configuration;
use Loupe\Loupe\LoupeFactory;
use Loupe\Loupe\SearchParameters;

$configuration = Configuration::create()
    ->withPrimaryKey('uuid') // optional, by default it's 'id'
    ->withSearchableAttributes(['firstname', 'lastname']) // optional, by default it's ['*'] - everything is indexed
    ->withFilterableAttributes(['departments', 'age'])
    ->withSortableAttributes(['lastname'])
    ->withTypoTolerance(TypoTolerance::create()->withFirstCharTypoCountsDouble(false)) // can be further fine-tuned but is enabled by default
;

$loupe = (new LoupeFactory())->create('path/to/my_loupe_data_dir', $configuration);
```

To create an in-memory search client:

```
$loupe = (new LoupeFactory())->createInMemory($configuration);
```

### Adding documents

[](#adding-documents)

```
$loupe->addDocuments([
    [
        'uuid' => 2,
        'firstname' => 'Uta',
        'lastname' => 'Koertig',
        'departments' => [
            'Development',
            'Backoffice',
        ],
        'age' => 29,
    ],
    [
        'uuid' => 6,
        'firstname' => 'Huckleberry',
        'lastname' => 'Finn',
        'departments' => [
            'Backoffice',
        ],
        'age' => 18,
    ],
]);
```

### Performing search

[](#performing-search)

```
$searchParameters = SearchParameters::create()
    ->withQuery('Gucleberry')
    ->withAttributesToRetrieve(['uuid', 'firstname'])
    ->withFilter("(departments = 'Backoffice' OR departments = 'Project Management') AND age > 17")
    ->withFacets(['departments', 'age'])
    ->withSort(['lastname:asc'])
;

$results = $loupe->search($searchParameters);
```

The `$results` array contains a list of search hits and metadata about the query.

```
print_r($results->toArray());

[
    'hits' => [
        [
            'uuid' => 6,
            'firstname' => 'Huckleberry'
        ]
    ],
    'query' => 'Gucleberry',
    'processingTimeMs' => 4,
    'hitsPerPage' => 20,
    'page' => 1,
    'totalPages' => 1,
    'totalHits' => 1,
    'facetDistribution' => [
        'departments' => [
            'Backoffice' => 1,
        ],
    ],
    'facetStats' => [
        'age' => [
            'min' => 18,
            'max' => 18,
        ],
    ],
]
```

Docs
----

[](#docs)

The documentation is available at [loupe-php.github.io/loupe](https://loupe-php.github.io/loupe/).

- [Schema](./docs/schema.md)
- [Configuration](./docs/configuration.md)
- [Indexing](./docs/indexing.md)
- [Searching](./docs/searching.md)
- [Browsing](./docs/browsing.md)
- [Ranking](./docs/ranking.md)
- [Tokenizer](./docs/tokenizer.md)
- [Performance](./docs/performance.md)

"Why Loupe?" you ask? "Loupe" means "magnifier" in French and I felt like this was the appropriate choice for this library after having given [my PHP crawler library](https://github.com/terminal42/escargot) a French name :-)

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance89

Actively maintained with recent releases

Popularity55

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.6% 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

Every ~13 days

Total

72

Last Release

53d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/481937?v=4)[Yanick Witschi](/maintainers/Toflar)[@Toflar](https://github.com/Toflar)

---

Top Contributors

[![Toflar](https://avatars.githubusercontent.com/u/481937?v=4)](https://github.com/Toflar "Toflar (278 commits)")[![daun](https://avatars.githubusercontent.com/u/22225348?v=4)](https://github.com/daun "daun (21 commits)")[![alexander-schranz](https://avatars.githubusercontent.com/u/1698337?v=4)](https://github.com/alexander-schranz "alexander-schranz (8 commits)")[![MaximilianKresse](https://avatars.githubusercontent.com/u/545671?v=4)](https://github.com/MaximilianKresse "MaximilianKresse (3 commits)")[![discordier](https://avatars.githubusercontent.com/u/940331?v=4)](https://github.com/discordier "discordier (2 commits)")[![zonky2](https://avatars.githubusercontent.com/u/1045318?v=4)](https://github.com/zonky2 "zonky2 (2 commits)")[![doishub](https://avatars.githubusercontent.com/u/48379929?v=4)](https://github.com/doishub "doishub (1 commits)")[![norkunas](https://avatars.githubusercontent.com/u/2722872?v=4)](https://github.com/norkunas "norkunas (1 commits)")[![DumbergerL](https://avatars.githubusercontent.com/u/12397678?v=4)](https://github.com/DumbergerL "DumbergerL (1 commits)")[![panda-madness](https://avatars.githubusercontent.com/u/6180087?v=4)](https://github.com/panda-madness "panda-madness (1 commits)")[![qzminski](https://avatars.githubusercontent.com/u/193483?v=4)](https://github.com/qzminski "qzminski (1 commits)")[![nz-chris](https://avatars.githubusercontent.com/u/37297133?v=4)](https://github.com/nz-chris "nz-chris (1 commits)")[![fiedsch](https://avatars.githubusercontent.com/u/5047601?v=4)](https://github.com/fiedsch "fiedsch (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/loupe-loupe/health.svg)

```
[![Health](https://phpackages.com/badges/loupe-loupe/health.svg)](https://phpackages.com/packages/loupe-loupe)
```

###  Alternatives

[elasticsearch/elasticsearch

PHP Client for Elasticsearch

5.3k178.3M943](/packages/elasticsearch-elasticsearch)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k15.7k5](/packages/elgg-elgg)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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