Skip to content

Commit

Permalink
feat: ✨ implement new filter query param
Browse files Browse the repository at this point in the history
RE: #296

filter no longer an alias for fields param
  • Loading branch information
newgene committed Oct 20, 2023
1 parent ff98a8f commit 161e055
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion biothings/web/query/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,15 @@ def apply_extras(self, search, options):
# https://www.elastic.co/guide/en/elasticsearch/
# reference/current/index-modules.html

# Feature: filter
# apply extra filter (as query_string query) to filter results
# Ref: https://www.elastic.co/guide/en/elasticsearch/reference/8.10/query-dsl-bool-query.html
if options.filter:
search = search.filter("query_string", query=options.filter)

# Feature: post_filter
# -- implementation using query string matching
# Ref: https://www.elastic.co/guide/en/elasticsearch/reference/8.1/filter-search-results.html#post-filter
# Ref: https://www.elastic.co/guide/en/elasticsearch/reference/8.10/filter-search-results.html#post-filter
if options.post_filter:
search = search.post_filter("query_string", query=options["post_filter"])

Expand Down
5 changes: 4 additions & 1 deletion biothings/web/settings/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"raw": {"type": bool, "default": False},
"rawquery": {"type": bool, "default": False},
# query builder stage
"_source": {"type": list, "max": 1000, "alias": ("fields", "field", "filter")},
"_source": {"type": list, "max": 1000, "alias": ("fields", "field")},
"size": {"type": int, "max": 1000, "alias": "limit"},
# formatter stage
"dotfield": {"type": bool, "default": False},
Expand All @@ -124,6 +124,9 @@
**{
"from": {"type": int, "max": 10000, "alias": "skip"},
"sort": {"type": list, "max": 10},
# use to set extra filter, as a filter clause in a boolean query
"filter": {"type": str, "default": None},
# use to set post_filter query, this one does not impact facets
"post_filter": {"type": str, "default": None},
},
}, # for py3.9+, we can just use `|` operator like `COMMON_KWARGS.copy() | {...}`
Expand Down

0 comments on commit 161e055

Please sign in to comment.