From bade9952fa186b44acee8dd2898957e32f2c509b Mon Sep 17 00:00:00 2001 From: Alec Ritson Date: Mon, 21 Oct 2024 13:13:26 +0100 Subject: [PATCH] Update TypesenseEngine.php --- src/Engines/TypesenseEngine.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Engines/TypesenseEngine.php b/src/Engines/TypesenseEngine.php index 406bddd..51c8e5e 100644 --- a/src/Engines/TypesenseEngine.php +++ b/src/Engines/TypesenseEngine.php @@ -17,6 +17,18 @@ class TypesenseEngine extends AbstractEngine protected function buildSearchOptions(array $options, string $query, $useFacetFilters = true): array { $filters = collect($options['filter_by']); + $facets = $this->getFacetConfig(); + + $facetQuery = collect(); + + foreach ($facets as $facetConfig) { + if (empty($facetConfig['facet_query'])) { + continue; + } + $facetQuery->push($facetConfig['facet_query']); + } + + $facetQuery = $facetQuery->join(','); foreach ($this->filters as $key => $value) { $filters->push($key.':'.collect($value)->join(',')); @@ -43,6 +55,7 @@ protected function buildSearchOptions(array $options, string $query, $useFacetFi } $options['q'] = $query; + $options['facet_query'] = $facetQuery; $facets = $this->getFacetConfig(); $facetBy = array_keys($facets);