Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Oct 15, 2024
1 parent bc06fc1 commit 0a36b6d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
14 changes: 7 additions & 7 deletions packages/search/config/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
return [
'facets' => [
\Lunar\Models\Product::class => [
'brand' => [],
'size' => [],
'colour' => [
'Red' => [
'hex_value' => '#FF0000',
],
],
// 'brand' => [],
// 'size' => [],
// 'colour' => [
// 'Red' => [
// 'hex_value' => '#FF0000',
// ],
// ],
],
],
];
1 change: 1 addition & 0 deletions packages/search/src/Data/SearchFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class SearchFacet extends Data
{
public function __construct(
public string $label,
public string $field,
#[DataCollectionOf(FacetValue::class)]
public array $values,
Expand Down
2 changes: 1 addition & 1 deletion packages/search/src/Engines/MeilisearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class MeilisearchEngine extends AbstractEngine
{
public function get(): mixed
public function get(): SearchResults
{
$paginator = $this->getRawResults(function (Indexes $indexes, string $query, array $options) {

Expand Down
9 changes: 7 additions & 2 deletions packages/search/src/Engines/TypesenseEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TypesenseEngine extends AbstractEngine
{
public function get(): mixed
public function get(): SearchResults
{
$paginator = $this->getRawResults(function (Documents $documents, string $query, array $options) {

Expand All @@ -34,7 +34,10 @@ public function get(): mixed
}

$options['q'] = $query;
$options['facet_by'] = 'brand,colour,size';
$facets = $this->getFacetConfig();

$options['facet_by'] = implode(',', array_keys($facets));
$options['max_facet_values'] = 50;
$options['per_page'] = $this->perPage;
$options['sort_by'] = $this->sort;

Expand All @@ -60,6 +63,7 @@ public function get(): mixed

$facets = collect($results['facet_counts'])->map(
fn ($facet) => SearchFacet::from([
'label' => $this->getFacetConfig($facet['field_name'])['label'] ?? '',
'field' => $facet['field_name'],
'values' => collect($facet['counts'])->map(
fn ($value) => SearchFacet\FacetValue::from([
Expand All @@ -72,6 +76,7 @@ public function get(): mixed

foreach ($facets as $facet) {
$facetConfig = $this->getFacetConfig($facet->field);

foreach ($facet->values as $faceValue) {
if (empty($facetConfig[$faceValue->value])) {
continue;
Expand Down

0 comments on commit 0a36b6d

Please sign in to comment.