Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type filter search pagination #310

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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