getdkan / lunr.php
此包的最新版本(1.0.1)没有提供许可证信息。
1.0.1
2019-10-02 02:18 UTC
Requires
- markfullmer/porter2: ^1.0
Requires (Dev)
- phpunit/phpunit: ^8.2
This package is auto-updated.
Last update: 2024-08-29 05:24:27 UTC
README
此项目为 PHP 中的 Lunr.js 创建索引。这允许你在 PHP 应用程序中生成 Lunr.js 端点。
安装
composer install
测试
运行
./vendor/bin/phpunit
用法
生成索引的过程与 Lunr.js 类似。
// Instantiate the builder. $build = new BuildLunrIndex(); // Add a unique id. $build->ref('identifier'); // Add fields. $build->field("title"); $build->field("description"); // Add transforms to the pipeline. $pipeline->add('LunrPHP\LunrDefaultPipelines::trimmer'); $pipeline->add('LunrPHP\LunrDefaultPipelines::stop_word_filter'); $pipeline->add('LunrPHP\LunrDefaultPipelines::stemmer'); // Load docs. $string = file_get_contents("./fixtures/fixture.json"); $datasets = json_decode($string, true); // Add documents to the index. foreach ($datasets as $dataset) { $build->add($dataset); } // Output the index. $output = $build->output(); // Place wherever. echo json_encode($output, JSON_PRETTY_PRINT);
管道
有一个简单的 Pipeline 类,可以在索引过程中对术语执行转换。有关包含的管道,请参阅 src/pipelines.php
。
缺少的功能
此索引缺少增强和其他几个索引功能。