1. Go to this page and download the library: Download mapsight/pulp-search-index 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/ */
mapsight / pulp-search-index example snippets
use OpenMapsight\Pulp;
use OpenMapsight\pulp\File;
use OpenMapsight\PulpCache;
use OpenMapsight\PulpSearchIndex;
// source path => titles of the layers that show it
$sources = [
'/geojson/museums.geojson' => ['Museums'],
'/geojson/stops.geojson' => ['Stops', 'Public transport'],
];
$requests = [];
foreach ($sources as $path => $titles) {
$requests[] = $request = new File($path);
$request->content = $titles;
}
Pulp::start()
->pipe(Pulp::src($requests))
->pipe(Pulp::each(
static fn(File $source): Pulp => Pulp::start()
// a source that fails keeps its last good copy
->pipe(PulpCache::remember(
Pulp::start()->pipe(Pulp::srcHttp('GET', 'https://www.example.org' . $source->fileName, ['timeout' => 30], $source->fileName)),
__DIR__ . '/cache',
['key' => 'search-' . sha1($source->fileName), 'ttl' => 0, 'fallbackToStale' => true],
))
->pipe(Pulp::map(static function (File $file) use ($source): File {
$file->titles = $source->content;
return $file;
})),
['skipExceptions' => true],
))
->pipe(PulpSearchIndex::index(options: ['skipExceptions' => true]))
->pipe(PulpSearchIndex::toDatabase(static fn(): PDO => new PDO($dsn, $user, $password)))
->run();