PHP code example of arnoson / kirby-loupe

1. Go to this page and download the library: Download arnoson/kirby-loupe 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/ */

    

arnoson / kirby-loupe example snippets


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

'arnoson.kirby-loupe' => [
    // Which pages to ate()->name() === 'item',

    // Which fields to ack, 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 'de']),
]

KirbyLoupe::reindex();

<a href="<?= $results->pagination()->prevPageURL() 

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

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