PHP code example of croox / statamic-meilisearch-extendable
1. Go to this page and download the library: Download croox/statamic-meilisearch-extendable 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/ */
croox / statamic-meilisearch-extendable example snippets
// config/statamic/search.php
return [
'drivers' => [
'meilisearch' => [
'credentials' => [
'url' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
'secret' => env('MEILISEARCH_KEY', ''),
],
],
],
'indexes' => [
'default' => [
'driver' => 'meilisearch',
'searchables' => [ 'all' ],
'snippet_length' => 90, // Optional
'meilisearch' => [
// 'filtering' => [
// // `type` can be one of the following:
// // - `statamic` (default): All filtering logic is done in PHP by statamic itself. Meilisearch fetches all results
// // without filtering or pagination. This can be inefficient for large datasets.
// // - `split`: Filtering that can be done in meilisearch (when the property is found in `filterableAttributes`) is done
// // in meilisearch, the rest is done in PHP.
// // - `meilisearch`: All filtering logic is done in meilisearch. If an unhandled where-case is found, then an exception
// // is thrown. This is the most efficient way to filter results and is 'default_sort' => [ 'date:desc' ],
//
// // Optional
// 'ranking_rules' => [ /* See https://www.meilisearch.com/docs/learn/filtering_and_sorting/sort_search_results#customize-ranking-rule-order-optional */ ]
// ],
// 'synonyms' => [
// // Searches for 'Dog' should also yield results containing 'Labrador'
// 'Dog' => [ 'Labrador' ],
//
// // Searches for 'Labrador' should not yield results containing 'Dog',
// // therefor the inverse synonym is not added.
// // 'Labrador' => [ 'Dog' ],
//
// // A shorthand is available by not using a key. This is equivalent to
// // 'Bed' => [ 'Matrace', 'Futon' ],
// // 'Matrace' => [ 'Bed', 'Futon' ],
// // 'Futon' => [ 'Bed', 'Matrace' ],
// [
// 'Bed',
// 'Matrace',
// 'Futon'
// ],
// ],
],
],
]
]
'indexes' => [
'default' => [
'meilisearch' => [
'sort_order' => [
// The attributes available for sorting must be listed under `available_fields`
'available_fields' => [ 'date', 'name' ],
// The sort order that is applied by default. If not specified, then the results
// are returned in an order that meilisearch deems most fitting to the search term.
'default_sort' => [ 'date:desc' ],
// Optional
'ranking_rules' => [ /* See https://www.meilisearch.com/docs/learn/filtering_and_sorting/sort_search_results#customize-ranking-rule-order-optional */ ]
],
]
],
]
'indexes' => [
'default' => [
'meilisearch' => [
'synonyms' => [
// Searches for 'Dog' should also yield results containing 'Labrador'
'Dog' => [ 'Labrador' ],
// Searches for 'Labrador' should not yield results containing 'Dog',
// therefor the inverse synonym is not added.
// 'Labrador' => [ 'Dog' ],
// A shorthand is available by not using a key. This is equivalent to
// 'Bed' => [ 'Matrace', 'Futon' ],
// 'Matrace' => [ 'Bed', 'Futon' ],
// 'Futon' => [ 'Bed', 'Matrace' ],
[
'Bed',
'Matrace',
'Futon'
]
],
]
],
]