Skip to content

Commit 7116204

Browse files
Merge #1005
1005: Adds documentation and an integration test case for the `distinct` keyword in index `search` r=sanders41 a=aweidner # Pull Request ## Related issue Fixes #989 ## What does this PR do? This pull requests adds documentation for the `distinct` keyword in the code samples file. It also adds an integration test case that exercises the `distinct` functionality of search. Note that the issue mentions adding the code sample for `distinct_attribute` but it looks like this code sample is already in place according to the docs: https://www.meilisearch.com/docs/learn/relevancy/distinct_attribute#setting-a-distinct-attribute-during-configuration. Happy to amend this PR if that's not the case and I'm misreading this. ## PR checklist Please check if your PR fulfills the following requirements: - [x ] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [ x] Have you read the contributing guidelines? - [ x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Adam Weidner <[email protected]> Co-authored-by: Adam Weidner <[email protected]>
2 parents e91b8a1 + c92439b commit 7116204

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ search_parameter_guide_attributes_to_search_on_1: |-
372372
client.index('movies').search('adventure', {
373373
'attributesToSearchOn': ['overview']
374374
})
375+
distinct_attribute_guide_filterable_1: |-
376+
client.index('products').update_filterable_attributes(['product_id', 'sku', 'url'])
377+
distinct_attribute_guide_distinct_parameter_1: |-
378+
client.index('products').search('white shirt', { distinct: 'sku' })
375379
add_movies_json_1: |-
376380
import json
377381

tests/index/test_index_search_meilisearch.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# pylint: disable=invalid-name
22

3+
from collections import Counter
4+
35
import pytest
46

57

@@ -506,3 +508,13 @@ def test_vector_search(index_with_documents_and_vectors):
506508
"", opt_params={"vector": [0.1, 0.2], "hybrid": {"semanticRatio": 1.0}}
507509
)
508510
assert len(response["hits"]) > 0
511+
512+
513+
def test_search_distinct(index_with_documents):
514+
index_with_documents().update_filterable_attributes(["genre"])
515+
response = index_with_documents().search("with", {"distinct": "genre"})
516+
genres = dict(Counter([x.get("genre") for x in response["hits"]]))
517+
assert isinstance(response, dict)
518+
assert len(response["hits"]) == 11
519+
assert genres == {None: 9, "action": 1, "Sci Fi": 1}
520+
assert response["hits"][0]["id"] == "399579"

0 commit comments

Comments
 (0)