This project creates an index for Lunr.js in PHP. This will allow you to generate a Lunr.js endpoint in a PHP application.
composer install
Run:
./vendor/bin/phpunit
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);
There is a simple Pipelines class to run transforms on the terms during indexing. See src/pipelines.php
for included pipelines.
This index is missing boosts and several other indexing features.