diff options
author | Bryan Newbold <bnewbold@archive.org> | 2021-04-30 15:04:54 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2021-04-30 15:04:56 -0700 |
commit | c6305dea8a37583d79c33388244bc5209fdd598b (patch) | |
tree | 5ec68d8945ca97347b26f4202d850d945f4f51d5 /fatcat_scholar/search.py | |
parent | d7f4e8c41462f2d44974fd66e2d8b0507b740084 (diff) | |
download | fatcat-scholar-c6305dea8a37583d79c33388244bc5209fdd598b.tar.gz fatcat-scholar-c6305dea8a37583d79c33388244bc5209fdd598b.zip |
web: don't clobber user input query when parsing
This is intended to be a UX improvement, to avoid adding double quotes
around the query a user has pasted in.
This does make the "parsing" behavior less transparent.
Diffstat (limited to 'fatcat_scholar/search.py')
-rw-r--r-- | fatcat_scholar/search.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py index a0cad2c..2c02a58 100644 --- a/fatcat_scholar/search.py +++ b/fatcat_scholar/search.py @@ -31,6 +31,7 @@ from fatcat_scholar.query_citation import try_fuzzy_match class FulltextQuery(BaseModel): q: Optional[str] = None + parsed_q: Optional[str] = None limit: Optional[int] = None offset: Optional[int] = None filter_time: Optional[str] = None @@ -259,7 +260,7 @@ def process_query(query: FulltextQuery) -> FulltextHits: # fall through to regular query, with pre-parsing query = copy.copy(query) if query.q: - query.q = pre_parse_query(query.q) + query.parsed_q = pre_parse_query(query.q) return do_fulltext_search(query) @@ -301,7 +302,7 @@ def do_fulltext_search( # this query use the fancy built-in query string parser basic_fulltext = Q( "query_string", - query=query.q, + query=query.parsed_q or query.q, default_operator="AND", analyze_wildcard=True, allow_leading_wildcard=False, @@ -337,7 +338,7 @@ def do_fulltext_search( # simplified version of basic_fulltext query, for highlighting highlight_query = Q( - "query_string", query=query.q, default_operator="AND", lenient=True, + "query_string", query=query.parsed_q or query.q, default_operator="AND", lenient=True, ) search = search.highlight( "abstracts.body", |