aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-06-29 18:04:48 -0700
committerBryan Newbold <bnewbold@archive.org>2020-06-29 18:04:50 -0700
commit25f501d2c655640a981d8727b7c278e81e08449f (patch)
tree1d0b5569931e6887a57cbd8359e299381be44ad3
parent097a7715cbe8ac43d18fe2755962ba52edb9a4ae (diff)
downloadfatcat-scholar-25f501d2c655640a981d8727b7c278e81e08449f.tar.gz
fatcat-scholar-25f501d2c655640a981d8727b7c278e81e08449f.zip
un-collapse only to same issue, not uncollapse-all-hits
This is user expecation, and was a lingering TODO with initial implementation.
-rw-r--r--fatcat_scholar/search.py24
-rw-r--r--fatcat_scholar/templates/search_macros.html2
2 files changed, 16 insertions, 10 deletions
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py
index e81da07..5997dda 100644
--- a/fatcat_scholar/search.py
+++ b/fatcat_scholar/search.py
@@ -28,7 +28,7 @@ class FulltextQuery(BaseModel):
filter_type: Optional[str] = None
filter_availability: Optional[str] = None
sort_order: Optional[str] = None
- collapse_pages: bool = True
+ collapse_key: Optional[str] = None
time_options: Any = {
"label": gettext("Release Date"),
"slug": "filter_time",
@@ -152,6 +152,16 @@ def do_fulltext_search(
f"Unknown 'filter_availability' parameter value: '{query.filter_availability}'"
)
+ if query.collapse_key:
+ search = search.filter("term", collapse_key=query.collapse_key)
+ else:
+ search = search.extra(
+ collapse={
+ "field": "collapse_key",
+ "inner_hits": {"name": "more_pages", "size": 0,},
+ }
+ )
+
# we combined several queries to improve scoring.
# this query use the fancy built-in query string parser
@@ -197,13 +207,6 @@ def do_fulltext_search(
number_of_fragments=2,
fragment_size=300,
)
- if query.collapse_pages:
- search = search.extra(
- collapse={
- "field": "collapse_key",
- "inner_hits": {"name": "more_pages", "size": 0,},
- }
- )
# sort order
if query.sort_order == "time_asc":
@@ -264,12 +267,15 @@ def do_fulltext_search(
for key in h:
if type(h[key]) is str:
h[key] = h[key].encode("utf8", "ignore").decode("utf8")
+ # ensure collapse_key is a single value, not an array
+ if type(h['collapse_key']) == list:
+ h['collapse_key'] = h['collapse_key'][0]
count_found: int = int(resp.hits.total)
count_returned = len(results)
# if we grouped to less than a page of hits, update returned count
- if query.collapse_pages and offset == 0 and (count_returned < limit):
+ if (not query.collapse_key) and offset == 0 and (count_returned < limit):
count_found = count_returned
return FulltextHits(
diff --git a/fatcat_scholar/templates/search_macros.html b/fatcat_scholar/templates/search_macros.html
index dd7c1e8..4c0b1de 100644
--- a/fatcat_scholar/templates/search_macros.html
+++ b/fatcat_scholar/templates/search_macros.html
@@ -156,7 +156,7 @@
{# ### COLLAPSED HITS #}
{% if paper._collapsed_count > 0 %}
<div style="padding-top: 0.5em;">
- <button class="ui compact basic blue button" form="search_form" type="submit" name="collapse_pages" value="false">
+ <button class="ui compact basic blue button" form="search_form" type="submit" name="collapse_key" value="{{ paper.collapse_key }}">
<i class="ui icon zoom-in"></i>
Show {{ paper._collapsed_count }} additional hits from this issue
</button>