Skip to content

Commit

Permalink
Merge pull request #310 from helxplatform/fix/type-filter-search
Browse files Browse the repository at this point in the history
Fix type filter search pagination
  • Loading branch information
YaphetKG authored Aug 14, 2023
2 parents 11d7846 + 063af0e commit c1b348e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/dug/core/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,10 @@ async def search_concepts(self, query, offset=0, size=None, types=None,
Changed to a long boolean match query to optimize search results
"""
query_dict = self._build_concepts_query(query, **kwargs)
total_items = await self.es.count(
body={"query": query_dict},
index="concepts_index")
# Get aggregated counts of biolink types
search_body = {"query": query_dict}
search_body['aggs'] = {'type-count': {'terms': {'field': 'type'}}}
# Add post_filter on types
if types:
assert isinstance(types, list)
if isinstance(types, list):
search_body['post_filter'] = {
"bool": {
"should": [
Expand All @@ -239,6 +234,18 @@ async def search_concepts(self, query, offset=0, size=None, types=None,
size=size,
explain=True
)
# Aggs/post_filter aren't supported by count
del search_body["aggs"]
if "post_filter" in search_body:
# We'll move the post_filter into the actual filter
search_body["query"]["bool"]["filter"]["bool"].update(
search_body["post_filter"]["bool"]
)
del search_body["post_filter"]
total_items = await self.es.count(
body=search_body,
index="concepts_index"
)

# Simplify the data structure we get from aggregations to put into the
# return value. This should be a count of documents hit for every type
Expand Down

0 comments on commit c1b348e

Please sign in to comment.