PHP code example of romanstruk / manticore-scout-engine
1. Go to this page and download the library: Download romanstruk/manticore-scout-engine 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/ */
romanstruk / manticore-scout-engine example snippets
public function scoutIndexMigration(): array
{
return [
'fields' => [
'id' => ['type' => 'bigint'],
'name' => ['type' => 'text'],
'category' => ['type' => 'string stored indexed'],// string|text [stored|attribute] [indexed]
],
'settings' => [
'min_prefix_len' => '3',
'min_infix_len' => '3',
'prefix_fields' => 'name',
'expand_keywords' => '1',
//'engine' => 'columnar', // [default] row-wise - traditional storage available in Manticore Search out of the box; columnar - provided by Manticore Columnar Library
],
];
}
'paginate_max_matches' => 1000,
'auto_escape_search_phrase' => true,
public function scoutMetadata(): array
{
return [
'cutoff' => 0,
'max_matches' => 1000,
];
}
use RomanStruk\ManticoreScoutEngine\Mysql\Builder;
$products = Product::search('the world is a wonderful place', function (Builder $builder) {
return $builder->setQuorumMatchingOperator(3);
})->get();
use RomanStruk\ManticoreScoutEngine\Mysql\Builder;
$products = Product::search('cat dog mouse', function (Builder $builder) {
return $builder->setProximitySearchOperator(5);
})->get();
use RomanStruk\ManticoreScoutEngine\Mysql\Builder;
//[doc] My cat loves my dog. The cat (Felis catus) is a domestic species of small carnivorous mammal.
$autocomplete = Product::search('my*',function (Builder $builder) {
return $builder->autocomplete(['"','^'], true); // "" ^ * allow full-text operators; stats - Show statistics of keywords, default is 0
})->raw();
// $autocomplete<array> "my", "my cat", "my dog"
use RomanStruk\ManticoreScoutEngine\Mysql\Builder;
//[doc] Crossbody Bag with Tassel
//[doc] microfiber sheet set
//[doc] Pet Hair Remover Glove
$result = Product::search('bagg with tasel',function (Builder $builder) {
return $builder->spellCorrection(true) // correct first word
})->raw();
// $result<array> 0 => ['suggest' => "bag"]
$result = Product::search('bagg with tasel',function (Builder $builder) {
return $builder->spellCorrection() // correct last word
})->raw();
// $result<array> 0 => ['suggest' => "tassel"]
$result = Product::search('bagg with tasel',function (Builder $builder) {
return $builder->spellCorrection(false, true) // correct last word and return sentence
})->raw();
// $result<array> 0 => ['suggest' => "bagg with tassel"]
use RomanStruk\ManticoreScoutEngine\Mysql\Builder;
//[doc] My cat loves my dogs.
$highlight = Product::search('dogs',
fn(Builder $builder) => $builder->highlight()->select(['id', 'name'])
)->raw();
// $highlight['hits']<array> [id => 1, name => 'My cat loves my dogs.', 'highlight' => 'My cat loves my <b>dogs</b>.']
use RomanStruk\ManticoreScoutEngine\Mysql\Builder;
//[doc] title => My cat loves my dogs. id => 1000
$highlight = Product::search('dogs',
fn(Builder $builder) => $builder->highlight()->select(['id', 'title'])
)->get();
// $highlight->getHighlight()[1000] => 'My cat loves my <b>dogs</b>.'