PHP code example of statamic-rad-pack / typesense
1. Go to this page and download the library: Download statamic-rad-pack/typesense 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/ */
statamic-rad-pack / typesense example snippets
'drivers' => [
// other drivers
'typesense' => [
'client' => [
'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
'nodes' => [
[
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
],
'nearest_node' => [
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
'connection_timeout_seconds' => env('TYPESENSE_CONNECTION_TIMEOUT_SECONDS', 2),
'healthcheck_interval_seconds' => env('TYPESENSE_HEALTHCHECK_INTERVAL_SECONDS', 30),
'num_retries' => env('TYPESENSE_NUM_RETRIES', 3),
'retry_interval_seconds' => env('TYPESENSE_RETRY_INTERVAL_SECONDS', 1),
],
],
],
'articles' => [
'driver' => 'typesense',
'searchables' => ['collection:articles'],
'fields' => ['id', 'title', 'url', 'type', 'content', 'locale'],
'settings' => [
'schema' => [
/*
Pass an optional schema, see the Typesense documentation for more info:
https://typesense.org/docs/26.0/api/collections.html#with-pre-defined-schema
*/
'fields' => [
[
'name' => 'company_name',
'type' => 'string'
],
[
'name' => 'num_employees',
'type' => 'int32'
],
[
'name' => 'country',
'type' => 'string',
'facet' => true
],
],
],
/*
Pass any of the options from https://typesense.org/docs/26.0/api/search.html#search-parameters
*/
'search_options' => [
/*
eg Specify a custom sort by order, see the Typesense documentation for more info:
https://typesense.org/docs/guide/ranking-and-relevance.html#ranking-based-on-relevance-and-popularity
*/
'sort_by' => '_text_match(buckets: 10):desc,weighted_score:desc',
],
],
],
php artisan vendor:publish --tag=statamic-typesense-config