Skip to content

Add new search parameters highlightPreTag, highlightPostTag and cropMarker #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,72 @@ def test_custom_search_params_with_string_list(index_with_documents):
assert 'title' in response['hits'][0]['_formatted']
assert 'overview' in response['hits'][0]['_formatted']

def test_custom_search_params_with_crop_marker(index_with_documents):
"""Tests search with a list of one string in query params."""
response = index_with_documents().search(
'dragon',
{
'limit': 1,
'attributesToCrop': ['overview'],
'cropLength': 10,
}
)
assert isinstance(response, dict)
assert len(response['hits']) == 1
assert '_formatted' in response['hits'][0]
assert 'overview' in response['hits'][0]['_formatted']
assert response['hits'][0]['_formatted']['overview'].count(' ') < 10
assert response['hits'][0]['_formatted']['overview'].count('…') == 2

def test_custom_search_params_with_customized_crop_marker(index_with_documents):
"""Tests search with a list of one string in query params."""
response = index_with_documents().search(
'dragon',
{
'limit': 1,
'attributesToCrop': ['overview'],
'cropLength': 10,
'cropMarker': '(ꈍᴗꈍ)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ꈍᴗꈍ)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stole your emojis 😍

}
)
assert isinstance(response, dict)
assert len(response['hits']) == 1
assert '_formatted' in response['hits'][0]
assert 'overview' in response['hits'][0]['_formatted']
assert response['hits'][0]['_formatted']['overview'].count('(ꈍᴗꈍ)') == 2

def test_custom_search_params_with_highlight_tag(index_with_documents):
"""Tests search with a list of one string in query params."""
response = index_with_documents().search(
'dragon',
{
'limit': 1,
'attributesToHighlight': ['*'],
}
)
assert isinstance(response, dict)
assert len(response['hits']) == 1
assert '_formatted' in response['hits'][0]
assert 'title' in response['hits'][0]['_formatted']
assert response['hits'][0]['_formatted']['title'] == 'How to Train Your <em>Dragon</em>: The Hidden World'

def test_custom_search_params_with_customized_highlight_tag(index_with_documents):
"""Tests search with a list of one string in query params."""
response = index_with_documents().search(
'dragon',
{
'limit': 1,
'attributesToHighlight': ['*'],
'highlightPreTag': '(⊃。•́‿•̀。)⊃ ',
'highlightPostTag': ' ⊂(´• ω •`⊂)',
}
)
assert isinstance(response, dict)
assert len(response['hits']) == 1
assert '_formatted' in response['hits'][0]
assert 'title' in response['hits'][0]['_formatted']
assert response['hits'][0]['_formatted']['title'] == 'How to Train Your (⊃。•́‿•̀。)⊃ Dragon ⊂(´• ω •`⊂): The Hidden World'

def test_custom_search_params_with_facets_distribution(index_with_documents):
index = index_with_documents()
update = index.update_filterable_attributes(['genre'])
Expand Down