def general_search(): try: args = request.args parameters = {'collection': None, 'size': SEARCH_CHUNK_SIZE, 'from_': 0, 'q': None, 'sort': None, "with_persons": False} parameters.update(PERSONS_SEARCH_DEFAULT_PARAMETERS) got_one_of_required_persons_params = False for param in parameters.keys(): if param in args: if param == "with_persons": parameters[param] = args[param].lower() in ["1", "yes", "true"] else: parameters[param] = args[param] if param in PERSONS_SEARCH_REQUIRES_ONE_OF and parameters[param]: got_one_of_required_persons_params = True if parameters["q"] or (parameters["collection"] == "persons" and got_one_of_required_persons_params): try: rv = es_search(**parameters) except Exception as e: logging.exception(e) return humanify({"error": e.message}, 500) for item in rv['hits']['hits']: enrich_item(item['_source'], collection_name=item['_type']) return humanify(rv) else: return humanify({"error": "You must specify a search query"}, 400) except Exception as e: logging.exception("unexpected error") return humanify(({"error": e.message}, 500))
def test_enrich_item_no_preview(app, mock_db): with app.app_context(): item = enrich_item({'Pictures': [ { 'IsPreview': 0, 'PictureId': 'ID' }, ], }, mock_db) assert item['main_image_url'] == \ 'https://storage.googleapis.com/bhs-flat-pics/ID.jpg'
def general_search(): args = request.args parameters = { 'collection': None, 'size': SEARCH_CHUNK_SIZE, 'from_': 0, 'q': None } for param in parameters.keys(): if param in args: parameters[param] = args[param] if not parameters['q']: abort(400, 'You must specify a search query') else: rv = es_search(**parameters) for item in rv['hits']['hits']: enrich_item(item['_source']) if not rv: abort(500, 'Sorry, the search cluster appears to be down') return humanify(rv)
def test_enrich_item_no_preview(app, mock_db): with app.app_context(): item = enrich_item( { 'Pictures': [ { 'IsPreview': 0, 'PictureId': 'ID' }, ], }, mock_db) assert item['main_image_url'] == \ 'https://storage.googleapis.com/bhs-flat-pics/ID.jpg'
def test_enrich_item_no_pictures(app, mock_db): with app.app_context(): item = enrich_item({}, mock_db) assert 'main_image_url' not in item