Skip to content

Commit

Permalink
Merge #1005
Browse files Browse the repository at this point in the history
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 <adam@adamweidner.com>
Co-authored-by: Adam Weidner <adam@anomalo.com>
  • Loading branch information
3 people authored Aug 20, 2024
2 parents e91b8a1 + c92439b commit 7116204
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ search_parameter_guide_attributes_to_search_on_1: |-
client.index('movies').search('adventure', {
'attributesToSearchOn': ['overview']
})
distinct_attribute_guide_filterable_1: |-
client.index('products').update_filterable_attributes(['product_id', 'sku', 'url'])
distinct_attribute_guide_distinct_parameter_1: |-
client.index('products').search('white shirt', { distinct: 'sku' })
add_movies_json_1: |-
import json
Expand Down
12 changes: 12 additions & 0 deletions tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pylint: disable=invalid-name

from collections import Counter

import pytest


Expand Down Expand Up @@ -506,3 +508,13 @@ def test_vector_search(index_with_documents_and_vectors):
"", opt_params={"vector": [0.1, 0.2], "hybrid": {"semanticRatio": 1.0}}
)
assert len(response["hits"]) > 0


def test_search_distinct(index_with_documents):
index_with_documents().update_filterable_attributes(["genre"])
response = index_with_documents().search("with", {"distinct": "genre"})
genres = dict(Counter([x.get("genre") for x in response["hits"]]))
assert isinstance(response, dict)
assert len(response["hits"]) == 11
assert genres == {None: 9, "action": 1, "Sci Fi": 1}
assert response["hits"][0]["id"] == "399579"

0 comments on commit 7116204

Please sign in to comment.