百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

loupe

> 编程语言
开源

一个全文搜索引擎,具有词法分析、词干提取、错别字容忍、过滤器和地理支持,仅基于 PHP 和 SQLite。

513 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个全文搜索引擎,具有词法分析、词干提取、错别字容忍、过滤器和地理支持,仅基于 PHP 和 SQLite。

Read the documentation: 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
  • crops attributes to show the most relevant context around matched terms
  • auto-detects languages
  • supports stemming
  • automatically decomposes English and German compound words, so searching for brush finds toothbrush
  • 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

If this is your first encounter with Loupe, you might want to read the blog post on Medium or as Markdown file 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 depends on many factors but here are some ballpark numbers based on indexing the ~32k movies fixture provided by MeiliSearch.

  • Querying for Amakin Dkywalker with typo tolerance and relevance ranking takes **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:

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

Adding documents

php
$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

php
$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.

php
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

The documentation is available at loupe-php.github.io/loupe.

  • Schema
  • Configuration
  • Indexing
  • Searching
  • Browsing
  • Ranking
  • Tokenizer
  • Performance

"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 a French name :-)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言