Skip to content

Commit

Permalink
Merge pull request #132 from meilisearch/meilisearch-bump-v0.13.0
Browse files Browse the repository at this point in the history
MeiliSearch Bump to v0.13.0
  • Loading branch information
curquiza authored Aug 3, 2020
2 parents 3017217 + 3b359cf commit 1f2827e
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 155 deletions.
8 changes: 0 additions & 8 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ update_displayed_attributes_1: |-
])
reset_displayed_attributes_1: |-
client.get_index('movies').reset_displayed_attributes()
get_accept_new_fields_1: |-
client.get_index('movies').get_accept_new_fields()
update_accept_new_fields_1: |-
client.get_index('movies').update_accept_new_fields(False)
get_index_stats_1: |-
client.get_index('movies').get_stats()
get_indexes_stats_1: |-
Expand Down Expand Up @@ -287,10 +283,6 @@ settings_guide_displayed_1: |-
'rank'
]
})
settings_guide_accept_new_fields_1: |-
client.get_index('movies').update_settings({
'acceptNewFields': False
})
documents_guide_add_movie_1: |-
client.get_index('movies').add_documents([{
'movie_id': '123sq178',
Expand Down
12 changes: 0 additions & 12 deletions meilisearch/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,6 @@ def get_keys(self):
"""
return self.http.get(self.config.paths.keys)

def get_sys_info(self):
"""Get system information of MeiliSearch
Get information about memory usage and processor usage.
Returns
----------
sys_info: dict
Information about memory and processor usage.
"""
return self.http.get(self.config.paths.sys_info)

def get_version(self):
"""Get version MeiliSearch
Expand Down
1 change: 0 additions & 1 deletion meilisearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Config:
class Paths():
health = "health"
keys = 'keys'
sys_info = 'sys-info'
version = 'version'
index = 'indexes'
update = 'updates'
Expand Down
52 changes: 5 additions & 47 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import urllib
from datetime import datetime
from time import sleep
Expand Down Expand Up @@ -239,24 +238,18 @@ def search(self, query, opt_params=None):
results: `dict`
Dictionnary with hits, offset, limit, processingTime and initial query
"""
# Query parameters parsing
if opt_params is None:
opt_params = {}
for key in opt_params:
if key in ('facetsDistribution', 'facetFilters'):
opt_params[key] = json.dumps(opt_params[key])
elif isinstance(opt_params[key], list):
opt_params[key] = ','.join(opt_params[key])
params = {
body = {
'q': query,
**opt_params
}
return self.http.get(
'{}/{}/{}?{}'.format(
return self.http.post(
'{}/{}/{}'.format(
self.config.paths.index,
self.uid,
self.config.paths.search,
urllib.parse.urlencode(params))
self.config.paths.search),
body=body
)

def get_document(self, document_id):
Expand Down Expand Up @@ -780,41 +773,6 @@ def reset_synonyms(self):
self.__settings_url_for(self.config.paths.synonyms),
)

# ACCEPT-NEW-FIELDS SUB-ROUTES

def get_accept_new_fields(self):
"""
Get accept-new-fields value of an index
Returns
----------
settings: `bool`
Boolean containing the accept-new-fields value of the index
"""
return self.http.get(
self.__settings_url_for(self.config.paths.accept_new_fields)
)

def update_accept_new_fields(self, body):
"""
Update accept-new-fields value of an index
Parameters
----------
body: `bool`
Boolean containing the accept-new-fields value
Returns
----------
update: `dict`
Dictionnary containing an update id to track the action:
https://docs.meilisearch.com/references/updates.html#get-an-update-status
"""
return self.http.post(
self.__settings_url_for(self.config.paths.accept_new_fields),
body
)

# ATTRIBUTES FOR FACETING SUB-ROUTES

def get_attributes_for_faceting(self):
Expand Down
24 changes: 0 additions & 24 deletions meilisearch/tests/client/test_client_sysinfo_meilisearch.py

This file was deleted.

50 changes: 43 additions & 7 deletions meilisearch/tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,64 @@ def test_basic_search_with_empty_params(self):
assert response['hits'][0]['id'] == '166428'
assert '_formatted' not in response['hits'][0]

def test_basic_search_with_empty_query(self):
"""Tests search with empty query and empty params"""
response = self.index.search('')
assert isinstance(response, object)
assert len(response['hits']) == 0
assert response['query'] == ''

def test_basic_search_with_placeholder(self):
"""Tests search with no query [None] and empty params"""
response = self.index.search(None, {})
assert isinstance(response, object)
assert len(response['hits']) == 20

def test_custom_search(self):
"""Tests search with an simple query and custom parameter (attributesToHighlight)"""
response = self.index.search(
'Dragon',
{
'attributesToHighlight': 'title'
'attributesToHighlight': ['title']
}
)
assert isinstance(response, object)
assert response['hits'][0]['id'] == '166428'
assert '_formatted' in response['hits'][0]
assert 'dragon' in response['hits'][0]['_formatted']['title'].lower()

def test_custom_search_with_empty_query(self):
"""Tests search with empty query and custom parameter (attributesToHighlight)"""
response = self.index.search(
'',
{
'attributesToHighlight': ['title']
}
)
assert isinstance(response, object)
assert len(response['hits']) == 0
assert response['query'] == ''

def test_custom_search_with_placeholder(self):
"""Tests search with no query [None] and custom parameter (limit)"""
response = self.index.search(
None,
{
'limit': 5
}
)
assert isinstance(response, object)
assert len(response['hits']) == 5

def test_custom_search_params_with_wildcard(self):
"""Tests search with '*' in query params"""
response = self.index.search(
'a',
{
'limit': 5,
'attributesToHighlight': '*',
'attributesToRetrieve': '*',
'attributesToCrop': '*',
'attributesToHighlight': ['*'],
'attributesToRetrieve': ['*'],
'attributesToCrop': ['*'],
}
)
assert isinstance(response, object)
Expand All @@ -76,9 +112,9 @@ def test_custom_search_params_with_simple_string(self):
'a',
{
'limit': 5,
'attributesToHighlight': 'title',
'attributesToRetrieve': 'title',
'attributesToCrop': 'title',
'attributesToHighlight': ['title'],
'attributesToRetrieve': ['title'],
'attributesToCrop': ['title'],
}
)
assert isinstance(response, object)
Expand Down
14 changes: 5 additions & 9 deletions meilisearch/tests/settings/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ def test_get_settings_default(self):
for rule in self.default_ranking_rules:
assert rule in response['rankingRules']
assert response['distinctAttribute'] is None
assert response['searchableAttributes'] == []
assert response['displayedAttributes'] == []
assert response['searchableAttributes'] == ['*']
assert response['displayedAttributes'] == ['*']
assert response['stopWords'] == []
assert response['synonyms'] == {}
assert response['acceptNewFields'] is True

def test_update_settings(self):
"""Tests updating some settings"""
Expand All @@ -52,10 +51,9 @@ def test_update_settings(self):
assert response['distinctAttribute'] is None
for attribute in self.new_settings['searchableAttributes']:
assert attribute in response['searchableAttributes']
assert response['displayedAttributes'] == []
assert response['displayedAttributes'] == ['*']
assert response['stopWords'] == []
assert response['synonyms'] == {}
assert response['acceptNewFields'] is True

def test_reset_settings(self):
"""Tests resetting default settings"""
Expand All @@ -68,9 +66,7 @@ def test_reset_settings(self):
for rule in self.default_ranking_rules:
assert rule in response['rankingRules']
assert response['distinctAttribute'] is None
for attribute in self.new_settings['searchableAttributes']:
assert attribute in response['searchableAttributes']
assert attribute in response['displayedAttributes']
assert response['displayedAttributes'] == ['*']
assert response['searchableAttributes'] == ['*']
assert response['stopWords'] == []
assert response['synonyms'] == {}
assert response['acceptNewFields'] is True

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ def test_get_displayed_attributes(self):
""" Tests getting the displayed attributes before and after indexing a dataset """
response = self.index.get_displayed_attributes()
assert isinstance(response, object)
assert response == []
assert response == ['*']
response = self.index.add_documents(self.dataset_json, primary_key='id')
self.index.wait_for_pending_update(response['updateId'])
get_attributes = self.index.get_displayed_attributes()
for attribute in self.displayed_attributes:
assert attribute in get_attributes
assert get_attributes == ['*']

def test_update_displayed_attributes(self):
"""Tests updating the displayed attributes"""
get_attributes = self.index.get_displayed_attributes()
response = self.index.update_displayed_attributes(get_attributes[1:])
response = self.index.update_displayed_attributes(self.displayed_attributes)
self.index.wait_for_pending_update(response['updateId'])
get_attributes_new = self.index.get_displayed_attributes()
assert len(get_attributes_new) == len(self.displayed_attributes) - 1
assert get_attributes[0] not in get_attributes_new
assert len(get_attributes_new) == len(self.displayed_attributes)
for attribute in self.displayed_attributes:
assert attribute in get_attributes_new

def test_reset_displayed_attributes(self):
"""Tests the reset of displayedAttributes to default values (in dataset)"""
Expand All @@ -48,6 +47,4 @@ def test_reset_displayed_attributes(self):
assert 'updateId' in response
self.index.wait_for_pending_update(response['updateId'])
get_attributes = self.index.get_displayed_attributes()
assert len(get_attributes) == len(self.displayed_attributes)
for attribute in self.displayed_attributes:
assert attribute in get_attributes
assert get_attributes == ['*']
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ def test_get_searchable_attributes(self):
"""Tests getting the searchable attributes on an empty and populated index"""
response = self.index.get_searchable_attributes()
assert isinstance(response, object)
assert response == []
assert response == ['*']
response = self.index.add_documents(self.dataset_json, primary_key='id')
self.index.wait_for_pending_update(response['updateId'])
get_attributes = self.index.get_searchable_attributes()
for attribute in self.full_searchable_attributes:
assert attribute in get_attributes
assert get_attributes == ['*']


def test_update_searchable_attributes(self):
Expand All @@ -41,6 +40,7 @@ def test_update_searchable_attributes(self):
assert 'updateId' in response
self.index.wait_for_pending_update(response['updateId'])
response = self.index.get_searchable_attributes()
assert len(response) == len(self.new_searchable_attributes)
for attribute in self.new_searchable_attributes:
assert attribute in response

Expand All @@ -51,5 +51,4 @@ def test_reset_searchable_attributes(self):
assert 'updateId' in response
self.index.wait_for_pending_update(response['updateId'])
response = self.index.get_searchable_attributes()
for attribute in self.full_searchable_attributes:
assert attribute in response
assert response == ['*']

0 comments on commit 1f2827e

Please sign in to comment.