Skip to content

Commit

Permalink
Immutable settings (#22)
Browse files Browse the repository at this point in the history
* Make setting immutable between each scrape

* Validate that custom settings is a dictionary

* Change value of custom settings in tests

* lint

* Removed unecessary try and catch

* Update scraper/src/meilisearch_helper.py

Co-authored-by: Clémentine Urquizar <clementine@meilisearch.com>

Co-authored-by: Clémentine Urquizar <clementine@meilisearch.com>
  • Loading branch information
bidoubiwa and curquiza authored Jun 3, 2020
1 parent 39faa3c commit 6e4dd81
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions scraper/src/config/config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def validate(self):
list):
raise Exception('stop_urls should be list')

# Custom settings must be a dict
if self.config.custom_settings and not isinstance(self.config.custom_settings,
dict):
raise Exception('custom_settings must be a dictionary')

if self.config.js_render and not isinstance(self.config.js_render,
bool):
raise Exception('js_render should be boolean')
Expand Down
1 change: 1 addition & 0 deletions scraper/src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def run_config(config):
config.app_id,
config.api_key,
config.index_uid,
config.custom_settings
)

root_module = 'src.' if __name__ == '__main__' else 'scraper.src.'
Expand Down
5 changes: 3 additions & 2 deletions scraper/src/meilisearch_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ class MeiliSearchHelper:
'acceptNewFields': False
}

def __init__(self, host_url, api_key, index_uid):
def __init__(self, host_url, api_key, index_uid, custom_settings):
self.meilisearch_client = meilisearch.Client(host_url, api_key)
self.__delete_and_create_index(index_uid)
self.meilisearch_index = self.__delete_and_create_index(index_uid)
self.meilisearch_index.update_settings(MeiliSearchHelper.SETTINGS)
settings = {**MeiliSearchHelper.SETTINGS, **custom_settings}
self.meilisearch_index.update_settings(settings)

def add_records(self, records, url, from_sitemap):
"""Add new records to the index"""
Expand Down
2 changes: 1 addition & 1 deletion scraper/src/tests/config_loader/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def config(additional_config={}):
'allowed_domains': 'allowed_domains',
'api_key': 'api_key',
'app_id': 'app_id',
'custom_settings': 'custom_settings',
'custom_settings': {},
'hash_strategy': 'hash_strategy',
'index_uid': 'index_uid',
'selectors': [],
Expand Down

0 comments on commit 6e4dd81

Please sign in to comment.