aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-04-30 15:04:54 -0700
committerBryan Newbold <bnewbold@archive.org>2021-04-30 15:04:56 -0700
commitc6305dea8a37583d79c33388244bc5209fdd598b (patch)
tree5ec68d8945ca97347b26f4202d850d945f4f51d5
parentd7f4e8c41462f2d44974fd66e2d8b0507b740084 (diff)
downloadfatcat-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.
-rw-r--r--fatcat_scholar/search.py7
-rw-r--r--fatcat_scholar/templates/base.html3
2 files changed, 7 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",
diff --git a/fatcat_scholar/templates/base.html b/fatcat_scholar/templates/base.html
index acdf15c..51af546 100644
--- a/fatcat_scholar/templates/base.html
+++ b/fatcat_scholar/templates/base.html
@@ -125,6 +125,9 @@
<div class="ui action input large fluid">
<input type="search" placeholder="{{ _("by title, authors, keywords...") }}" name="q" aria-label="{{ _('search for papers') }}" required itemprop="query-input" style="border-radius: 0; border: 1px #999 solid;" {% if query and query.q %}value="{{ query.q }}"{% endif %}>
<button id="search_submit_button" class="ui green button" style="border-radius: 0; background-color: #44a25a; font-size: 1.2rem;">{{ _("Search") }}</button>
+ {% if query and query.parsed_q %}
+ <!-- parsed query: {{ query.parsed_q }} -->
+ {% endif %}
</div>
</div>
</form>