Skip to content

Commit

Permalink
Merge pull request #989 from SlovakNationalGallery/MG-74
Browse files Browse the repository at this point in the history
[item] prioritize suggestions with images
  • Loading branch information
rastislav-chynoransky authored Apr 9, 2024
2 parents 8654a60 + 04d9a92 commit f19f16f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/Elasticsearch/Repositories/ItemRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public static function buildSuggestionsQuery(string $search): array
'operator' => 'and',
],
],
'should' => [
['term' => ['has_image' => true]],
],
'filter' => [
['term' => ['frontend' => Frontend::get()]],
],
Expand Down
25 changes: 25 additions & 0 deletions tests/Elasticsearch/Repositories/ItemRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,29 @@ public function testSimilarByColor()
$this->assertTrue($similar_by_color->first()->is($similar_item));
$this->assertFalse($similar_by_color->contains($dissimilar_item));
}

public function testSuggestions()
{
$withImage = Item::factory()->make([
'title' => 'apple',
'has_image' => true,
]);

$withoutImage = Item::factory()->make([
'title' => 'apple apple',
'has_image' => false,
]);

foreach ([$withImage, $withoutImage] as $item) {
$this->repository->index($item);
}
$this->repository->refreshIndex();

$suggestions = $this->repository
->getSuggestions(2, 'apple')
->getCollection();

$this->assertTrue($suggestions[0]->is($withImage));
$this->assertTrue($suggestions[1]->is($withoutImage));
}
}

0 comments on commit f19f16f

Please sign in to comment.