-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig.php
More file actions
91 lines (89 loc) · 3.04 KB
/
config.php
File metadata and controls
91 lines (89 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use craft\elements\db\EntryQuery;
use craft\elements\Entry;
use fostercommerce\meilisearch\builders\IndexBuilder;
use fostercommerce\meilisearch\builders\IndexSettingsBuilder;
return [
/**
* The host URL used when communicating with the Meilisearch instance.
*/
'meiliHostUrl' => 'http://localhost:7700',
/**
* Meilisearch Admin API key used for updating index settings and syncing index data.
*/
'meiliAdminApiKey' => '<Meilisearch Admin Key>',
/**
* Meilisearch Search API key used when performing searches using the plugins search service or with the Twig variable.
*/
'meiliSearchApiKey' => '<Meilisearch Search Key>',
/**
* The maximum number of times a sync job can recursively spawn dependent sync jobs.
*/
'maxDependencyRecursionLevel' => 4,
/**
* A list of indices that can be created and/or searched.
*/
'indices' => [
/**
* The key here is the index handle you would use when running commands against a specific index.
*
* This means you can always refer to the same index handle in code and in commands.
*
* For example:
*
* ```bash
* craft meilisearch-connect/sync/flush pages
* craft meilisearch-connect/sync/index pages
* ```
*/
'pages' => IndexBuilder::fromSettings( // Use IndexBuilder::create() for search-only config.
IndexSettingsBuilder::create()
// Optionally configure ranking rules
// See https://www.meilisearch.com/docs/reference/api/settings#ranking-rules
->withRanking([
'customRanking:desc',
'words',
'exactness',
'proximity',
'attribute',
'date:desc',
'sort',
'typo',
])
// Optionally configure searchable attributes
// See https://www.meilisearch.com/docs/reference/api/settings#searchable-attributes
->withSearchableAttributes([
'id',
'title',
'section',
])
// Optionally configure faceting
// See https://www.meilisearch.com/docs/reference/api/settings#faceting-object for options
->withFaceting([
'maxValuesPerFacet' => 300,
])
->build()
)
// Index ID is the actual ID of the index _in_ Meilisearch. This
// would normally be an environment variable if the ID is expected
// to be different across environments.
->withIndexId('pages')
// Set your element/entry query and include a transform function which will be applied to every
// item in the query.
->withElementQuery(
// Alternatively, you can pass the query in directly, but some filters, such as `site()` can run a query immediately which might cause issues when parsing config.
static fn (): EntryQuery => Entry::find(), // Get all entries
// Return false from this transform function to prevent this item from being indexed.
static fn (Entry $entry): array => [
// Transform the entry
'id' => $entry->id,
'title' => $entry->title,
'section' => $entry->section->handle ?? '',
'url' => $entry->getUrl(),
// Any other fields you would like to index
]
)
// Turn the configuration into an array that Craft can use to configure the plugin.
->build(),
],
];