`public function listings()` { $class...
# community-help
s
public function listings()
{ $classifiedListingsQuery = ClassifiedListing::search($this->search, function(Documents $document, string $query, array $options){ $options['filter_by'] = 'price:[' . $this->minPrice . '..' . $this->maxPrice . ']'; // Include facet parameter $options['facet_by'] = 'category_path, brand_slug, listing_condition'; // $options['max_facet_values'] = '22'; if($this->selectedFacetName && $this->selectedFacetValue){ $options['facet_query'] = $this->selectedFacetName . ':' . $this->selectedFacetValue; $options['filter_by'] = $this->selectedFacetName . ':=' . $this->selectedFacetValue; } $options['sort_by'] = $this->sort; $options['per_page'] = 12; $response = $document->search($options); $this->facetCounts = collect(); // Check if facet counts are present in the response if (isset($response['facet_counts'])) { // Loop through each facet count foreach ($response['facet_counts'] as $facetCount) { // Extract field name $fieldName = $facetCount['field_name']; // Extract counts $counts = collect($facetCount['counts'])->map(function ($count) { return [ 'value' => $count['value'], 'count' => $count['count'], ]; }); // Add facet counts to the collection $this->facetCounts->put($fieldName, $counts); } } $this->resetPage(); return $response; }); return $classifiedListingsQuery->paginate(15); }