aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2024-08-01 18:43:51 +0100
committerArun Isaac2024-08-01 18:45:45 +0100
commit4b2e9f3fb3383421d7a55df5399aab71e0cc3b4f (patch)
tree9efad10bbe8fda40bd909489d52c81e143ffe351
parenta37622b466f9f045db06a6f07e88fcf81b176f91 (diff)
downloadgenenetwork3-4b2e9f3fb3383421d7a55df5399aab71e0cc3b4f.tar.gz
Stem group field regardless of case.
* gn3/api/search.py (parse_boolean_prefixed_field): New function. (parse_query): Use parse_boolean_prefixed_field for the group field.
-rw-r--r--gn3/api/search.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py
index 05a989c..e4e2d9f 100644
--- a/gn3/api/search.py
+++ b/gn3/api/search.py
@@ -194,6 +194,14 @@ def parse_location_field(species_query: xapian.Query,
.maybe(xapian.Query.MatchNothing, make_query))
+def parse_boolean_prefixed_field(prefix: str, query: bytes) -> xapian.Query:
+ """Parse boolean prefixed field and return a xapian query."""
+ # For some reason, xapian does not stem boolean prefixed fields
+ # when the query starts with a capital letter. We need it to stem
+ # always. Hence this function.
+ return xapian.Query(prefix + query.decode("utf-8").lower())
+
+
# pylint: disable=too-many-locals
def parse_query(synteny_files_directory: Path, query: str):
"""Parse search query using GeneNetwork specific field processors."""
@@ -204,7 +212,8 @@ def parse_query(synteny_files_directory: Path, query: str):
chromosome_prefix = "XC"
queryparser.add_boolean_prefix("author", "A")
queryparser.add_boolean_prefix("species", species_prefix)
- queryparser.add_boolean_prefix("group", "XG")
+ queryparser.add_boolean_prefix("group",
+ FieldProcessor(partial(parse_boolean_prefixed_field, "XG")))
queryparser.add_boolean_prefix("tissue", "XI")
queryparser.add_boolean_prefix("dataset", "XDS")
queryparser.add_boolean_prefix("symbol", "XY")