getdkan / lunr.php
Installs: 8 483
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 5
Requires
- markfullmer/porter2: ^1.0
Requires (Dev)
- phpunit/phpunit: ^8.2
This package is auto-updated.
Last update: 2024-11-29 06:21:46 UTC
README
This project creates an index for Lunr.js in PHP. This will allow you to generate a Lunr.js endpoint in a PHP application.
Installation
composer install
Tests
Run:
./vendor/bin/phpunit
Usage
Generating an index is similar to 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);
Pipelines
There is a simple Pipelines class to run transforms on the terms during indexing. See src/pipelines.php
for included pipelines.
Missing Features
This index is missing boosts and several other indexing features.