studioespresso / craft-scout

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.
MIT License
81 stars 54 forks source link

Support replica index configuration #275

Closed johnnynotsolucky closed 9 months ago

johnnynotsolucky commented 9 months ago

Resolves #114

This PR adds a flag on ScoutIndex to flag an index as a replica which prevents it from being sync'd by the plugin.

Replica indices can be configured by adding them to the indices property in config like you would a regular index with the exception of setting the flag using ->replicaIndex(true).

[
    'indices' => [
        ScoutIndex::create('Products')
            // ...
            ->indexSettings(
                IndexSettings::create()->replicas(['virtual(Products_desc)'])
            )
    ],
    [
        ScoutIndex::create('Products_desc')
            ->replicaIndex(true)
            ->indexSettings(IndexSettings::create()->customRanking(['desc(price)'])),
    ],
]

This roughly follows how Algolia recommends configuring replicas in code: https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/how-to/sort-by-attribute/#example-relevant-sort-with-a-virtual-replica

Updated utilities view:

image

janhenckens commented 9 months ago

Thanks @johnnynotsolucky, I'll have a look and if all goes well this should be included in the next release!

janhenckens commented 9 months ago

Looks good, merged and ready for release. Waiting for a couple of other things but this should be out Sunday at the latest!

Thanks again!

janhenckens commented 8 months ago

This is now out in 3.3.0.