定制 arnoson/kirby-loupe 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

arnoson/kirby-loupe

Composer 安装命令:

composer require arnoson/kirby-loupe

包简介

Search Kirby with Loupe

README 文档

README

Kirby Loupe

A thin wrapper around Loupe, an SQLite based, PHP-only fulltext search engine.

Key Features

  • 🎯 Typo tolerant / fuzzy search
  • 🔍 Filtering and sorting
  • 📄 Built-in pagination
  • 🌍 Works everywhere, no SQLite extensions needed
  • ⚡ Decent performance (~100ms for 5000 documents, ~300ms on low-end shared hosting)

Install

composer require arnoson/kirby-loupe

Usage

You have to index your existing content once. After the initial indexing the index will be updated automatically via Kirby's page hooks.

// Call this once or use the panel field (see #reindex)
arnoson\KirbyLoupe::reindex();
// Inside your template/controller.

$results = KirbyLoupe::search(
  // See https://github.com/loupe-php/loupe/blob/main/docs/searching.md#query
  query: "...",

  //  See https://github.com/loupe-php/loupe/blob/main/docs/searching.md#filter
  filter: "interests = 'music'",

  // See https://github.com/loupe-php/loupe/blob/main/docs/searching.md#sort
  sort: ["title:asc"],

  // Loupe always paginates the results, default is 20.
  paginate: 100
);

foreach ($results as $result) {
  echo $result->title();
}

Options

'arnoson.kirby-loupe' => [
    // Which pages to include in the search.
    'pages' => fn($page) => $page->intendedTemplate()->name() === 'item',

    // Which fields to include in the search.
    'fields' => [
        // Can be just the field name ...
        'title',
        // or a callback, transforming the field for better searching.
        'text' => fn($page) => strip_tags($page->text()),
        // loupe also supports so called multi fields (arrays) allowing you to
        // do advanced filtering.
        'interests' => fn($page) => $page->interests()->split(),
    ],

    // Which fields to include in the text search, default is all fields.
    'searchable' => ['title', 'text'],

    // Which fields to include in the filtering.
    'filterable' => ['interests'],

    // Which fields to include in the sorting.
    'sortable' => ['title'],

    // Additional loupe configuration, see: https://github.com/loupe-php/loupe/blob/main/docs/configuration.md
    'configuration' => fn() => Loupe\Loupe\Configuration::create()
      ->withLanguages(['en', 'fr', 'de']),
]

Reindex

This plugin will automatically update Loupe's search index via page hooks. But for your initial content, or after you have manually uploaded content, you will need to index your site explicitly. To do so either call

KirbyLoupe::reindex();

Or use the panel field

fields:
  reindex:
    type: loupe-reindex

As indexing large numbers of pages (thousands) can potentially break due to maximum execution time, especially on shared hosting, indexing via the Panel is done in chunks. The default is 100, so 100 pages will be indexed at a time and a progress bar will be displayed. If you only have a small number of pages, or a good enough server, you can disable chunks and index all pages at once.

fields:
  reindex:
    type: loupe-reindex
    chunk: false # disable chunks
    chunk: 500 # or increase chunk size

Pagination

The result has a pagination attached, so you can build your navigation, see the /example/site/templates/default for a full example.

<a href="<?= $results->pagination()->prevPageURL() ?>">‹</a>
<a href="<?= $results->pagination()->nextPageURL() ?>">›</a>

This uses Kirby's native pagination class. You can pass advanced navigation options in search():

KirbyLoupe::search(
  paginate: [
    "limit" => 50,
    "method" => "query",
    "variable" => "p",
  ]
);
// This will use 50 results per page and URLs in the format example.com/?p=10

Loupe Search Result

// Access to the raw loupe search result.
dump($results->searchResult()->getHits());

See example/site/templates/default.php for a more advanced example.

arnoson/kirby-loupe 适用场景与选型建议

arnoson/kirby-loupe 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.7k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2025 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「search」 「sqlite」 「filter」 「index」 「kirby」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 arnoson/kirby-loupe 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arnoson/kirby-loupe 我们能提供哪些服务?
定制开发 / 二次开发

基于 arnoson/kirby-loupe 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 40
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 40
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-04