PHP code example of getdkan / lunr.php

1. Go to this page and download the library: Download getdkan/lunr.php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

getdkan / lunr.php example snippets



  // 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);