Skip to content
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

Apply documents changes #481

Merged
merged 7 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ def get_documents(self, parameters: Optional[Dict[str, Any]] = None) -> List[Dic
Parameters
----------
parameters (optional):
parameters accepted by the get documents route: https://docs.meilisearch.com/reference/api/documents.html#get-all-documents
parameters accepted by the get documents route: https://docs.meilisearch.com/reference/api/documents.html#get-documents
alallema marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
document:
List of dictionaries containing the documents information.
Dictionary with limit, offset, total and results a list of dictionaries containing the documents information.

Raises
------
Expand Down
31 changes: 15 additions & 16 deletions tests/index/test_index_document_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
def test_get_documents_default(empty_index):
"""Tests getting documents on a clean index."""
response = empty_index().get_documents()
assert isinstance(response, list)
assert response == []
assert isinstance(response['results'], list)
assert response['results'] == []

def test_add_documents(empty_index, small_movies):
"""Tests adding new documents to a clean index."""
Expand All @@ -36,7 +36,6 @@ def test_add_documents_in_batches(
response = index.add_documents_in_batches(small_movies, batch_size, primary_key)
assert ceil(len(small_movies) / batch_size) == len(response)

print(response, '\n', '\n')
for r in response:
assert 'uid' in r
update = index.wait_for_task(r['uid'])
Expand All @@ -60,38 +59,38 @@ def test_get_document_inexistent(empty_index):
def test_get_documents_populated(index_with_documents):
"""Tests getting documents from a populated index."""
response = index_with_documents().get_documents()
assert isinstance(response, list)
assert len(response) == 20
assert isinstance(response['results'], list)
assert len(response['results']) == 20

def test_get_documents_offset_optional_params(index_with_documents):
"""Tests getting documents from a populated index with optional parameters."""
index = index_with_documents()
response = index.get_documents()
assert isinstance(response, list)
assert len(response) == 20
assert isinstance(response['results'], list)
assert len(response['results']) == 20
response_offset_limit = index.get_documents({
'limit': 3,
'offset': 1,
'attributesToRetrieve': 'title'
'fields': 'title'
})
assert len(response_offset_limit) == 3
assert response_offset_limit[0]['title'] == response[1]['title']
assert len(response_offset_limit['results']) == 3
assert response_offset_limit['results'][0]['title'] == response['results'][1]['title']

def test_update_documents(index_with_documents, small_movies):
"""Tests updating a single document and a set of documents."""
index = index_with_documents()
response = index.get_documents()
response[0]['title'] = 'Some title'
update = index.update_documents([response[0]])
response['results'][0]['title'] = 'Some title'
update = index.update_documents([response['results'][0]])
assert isinstance(update, dict)
assert 'uid' in update
index.wait_for_task(update['uid'])
response = index.get_documents()
assert response[0]['title'] == 'Some title'
assert response['results'][0]['title'] == 'Some title'
update = index.update_documents(small_movies)
index.wait_for_task(update['uid'])
response = index.get_documents()
assert response[0]['title'] != 'Some title'
assert response['results'][0]['title'] != 'Some title'

@pytest.mark.parametrize('batch_size', [2, 3, 1000])
@pytest.mark.parametrize(
Expand Down Expand Up @@ -145,8 +144,8 @@ def test_delete_all_documents(index_with_documents):
assert 'uid' in response
index.wait_for_task(response['uid'])
response = index.get_documents()
assert isinstance(response, list)
assert response == []
assert isinstance(response['results'], list)
assert response['results'] == []

def test_add_documents_csv(empty_index, songs_csv):
"""Tests adding new documents to a clean index."""
Expand Down