PHP code example of cyber-duck / silverstripe-searchly
1. Go to this page and download the library: Download cyber-duck/silverstripe-searchly 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/ */
cyber-duck / silverstripe-searchly example snippets
$index = new SearchIndex(
'pages', // the index name, can be hard coded or better to pull from a .env var
'pages', // the searchly index _type
[Page::class] // an array of models to index, can be pages or non pages
);
$index = new SearchIndex(
'models', // the index name, can be hard coded or better to pull from a .env var
'models', // the searchly index _type
[
Page::class,
File::class
]
);
$index->index();
use CyberDuck\Searchly\Index\SearchIndex;
use SilverStripe\Assets\File;
use SilverStripe\Dev\BuildTask;
class SearchIndexTask extends BuildTask
{
protected $enabled = true;
protected $title = "Searchly Pages index task";
protected $description = "Indexes all site pages for use in searchly";
public function run($request)
{
$mappings = [
... // your configuration
];
$settings = [
... // your configuration
];
$index = new SearchIndex(
'pages', // the index name, can be hard coded or better to pull from a .env var
'pages', // the searchly index _type
[Page::class] // an array of models to index, can be pages or non pages
);
$index->resetIndex($mappings, $settings);
$index->index();
$index = new SearchIndex(
'files', // the index name, can be hard coded or better to pull from a .env var
'files', // the searchly index _type
[File::class] // an array of models to index, can be pages or non pages
);
$index->resetIndex($mappings, $settings);
$index->index();
}
}
public function run($request)
{
ini_set('max_execution_time', 300);
$index = new SearchIndex(...
use CyberDuck\Searchly\Index\SearchQuery;
$query = new SearchQuery(
$term, // the search term
'pages' // the index name, can be hard coded or better to pull from a .env var
);