Skip to content

Commit

Permalink
Merge pull request #71 from RedTurtle/ignore_non_existing_indexes
Browse files Browse the repository at this point in the history
Ignore non existing indexes in custom query rank
  • Loading branch information
cekk committed Aug 29, 2023
2 parents 40f67b9 + 1ee538b commit 9a5f357
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
5.2.1 (unreleased)
------------------

- Nothing changed yet.
- Ignore non-existing indexes in custom ranking.
[cekk]


5.2.0 (2023-08-21)
Expand Down
8 changes: 6 additions & 2 deletions src/redturtle/volto/restapi/services/search/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ def search(self, query=None):
queries.append(Eq(key, value["query"]))
elif key in ("b_start", "b_size"):
continue
elif index_type is None:
# skip, non-existent index
continue
else:
logger.warning(
f"Unsupported query parameter: {key} {index_type} {value}. Fall back to the standard query."
)
query = self.request.form.copy()
query = unflatten_dotted_dict(query)
return super(SearchHandler, self).search(query)

# term = query.pop("SearchableText")
Expand All @@ -118,8 +123,7 @@ def search(self, query=None):
)

return results
else:
return super(SearchHandler, self).search(query)
return super(SearchHandler, self).search(query)

def _parse_query(self, query):
query = super()._parse_query(query)
Expand Down
28 changes: 28 additions & 0 deletions src/redturtle/volto/tests/test_advancedsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,34 @@ def test_search_by_not_handled_index_type_return_standard_order(self):
["f1", "d1", "e1"], [item["@id"].split("/")[-1] for item in result["items"]]
)

def test_search_ignore_non_existent_indexes_and_return_custom_order_if_possible(
self,
):
response = self.api_session.get(
"/@search", params={"SearchableText": "foo", "xxx": True}
)
result = response.json()
self.assertEqual(result["items_total"], 3)
self.assertEqual(
["d1", "f1", "e1"], [item["@id"].split("/")[-1] for item in result["items"]]
)

# now repeat query with not handled index, and return standard order
response = self.api_session.get(
"/@search",
params={
"SearchableText": "foo",
"created.query": f"{DateTime().Date()}:00:00",
"created.range": "min",
"xxx": True,
},
)
result = response.json()
self.assertEqual(result["items_total"], 3)
self.assertEqual(
["f1", "d1", "e1"], [item["@id"].split("/")[-1] for item in result["items"]]
)


class AdvancedSearchWithFlagTest(BaseTest):
def test_by_default_flag_is_disabled(self):
Expand Down

0 comments on commit 9a5f357

Please sign in to comment.