4545from openlibrary .utils .solr import (
4646 DEFAULT_PASS_TIME_ALLOWED ,
4747 DEFAULT_SOLR_TIMEOUT_SECONDS ,
48+ SolrRequestLabel ,
4849)
4950
5051logger = logging .getLogger ("openlibrary.worksearch" )
@@ -195,24 +196,6 @@ def read_cookie():
195196 return 'details'
196197
197198
198- QueryLabel = Literal [
199- 'UNLABELLED' ,
200- 'BOOK_SEARCH' ,
201- 'BOOK_SEARCH_API' ,
202- 'BOOK_SEARCH_FACETS' ,
203- 'BOOK_CAROUSEL' ,
204- # Used for the internal request made by solr to choose the best edition
205- # during a normal book search
206- 'EDITION_MATCH' ,
207- 'LIST_SEARCH' ,
208- 'LIST_SEARCH_API' ,
209- 'SUBJECT_SEARCH' ,
210- 'SUBJECT_SEARCH_API' ,
211- 'AUTHOR_SEARCH' ,
212- 'AUTHOR_SEARCH_API' ,
213- ]
214-
215-
216199def run_solr_query ( # noqa: PLR0912
217200 scheme : SearchScheme ,
218201 param : dict | None = None ,
@@ -225,7 +208,7 @@ def run_solr_query( # noqa: PLR0912
225208 facet : bool | Iterable [str ] = True ,
226209 allowed_filter_params : set [str ] | None = None ,
227210 extra_params : list [tuple [str , Any ]] | None = None ,
228- query_label : QueryLabel = 'UNLABELLED' ,
211+ request_label : SolrRequestLabel = 'UNLABELLED' ,
229212):
230213 """
231214 :param param: dict of query parameters
@@ -245,7 +228,7 @@ def run_solr_query( # noqa: PLR0912
245228 * (('fq' , subquery ) for subquery in scheme .universe ),
246229 ('start' , offset ),
247230 ('rows' , rows ),
248- ('ol.label' , query_label ),
231+ ('ol.label' , request_label ),
249232 ('wt' , param .get ('wt' , 'json' )),
250233 ] + (extra_params or [])
251234
@@ -388,7 +371,7 @@ def do_search(
388371 rows = 100 ,
389372 facet = False ,
390373 spellcheck_count = None ,
391- query_label : QueryLabel = 'UNLABELLED' ,
374+ request_label : SolrRequestLabel = 'UNLABELLED' ,
392375):
393376 """
394377 :param param: dict of search url parameters
@@ -419,7 +402,7 @@ def do_search(
419402 spellcheck_count ,
420403 fields = list (fields ),
421404 facet = facet ,
422- query_label = query_label ,
405+ request_label = request_label ,
423406 )
424407
425408
@@ -619,7 +602,7 @@ def GET(self):
619602 page ,
620603 rows = rows ,
621604 spellcheck_count = 3 ,
622- query_label = 'BOOK_SEARCH' ,
605+ request_label = 'BOOK_SEARCH' ,
623606 )
624607 else :
625608 search_response = SearchResponse (
@@ -643,6 +626,7 @@ def works_by_author(
643626 facet = False ,
644627 has_fulltext = False ,
645628 query : str | None = None ,
629+ request_label : SolrRequestLabel = 'UNLABELLED' ,
646630):
647631 param = {'q' : query or '*:*' }
648632 if has_fulltext :
@@ -663,6 +647,7 @@ def works_by_author(
663647 "time_facet" ,
664648 ]
665649 ),
650+ request_label = request_label ,
666651 fields = list (
667652 WorkSearchScheme .default_fetched_fields | {'editions' , 'providers' }
668653 ),
@@ -750,7 +735,7 @@ def GET(self): # referenced subject_search
750735 def get_results (
751736 self ,
752737 req : ListSearchRequest ,
753- query_label : Literal ['LIST_SEARCH' , 'LIST_SEARCH_API' ],
738+ request_label : Literal ['LIST_SEARCH' , 'LIST_SEARCH_API' ],
754739 ):
755740 return run_solr_query (
756741 ListSearchScheme (),
@@ -759,7 +744,7 @@ def get_results(
759744 rows = req .limit ,
760745 fields = req .fields ,
761746 sort = req .sort ,
762- query_label = query_label ,
747+ request_label = request_label ,
763748 )
764749
765750
@@ -808,13 +793,15 @@ class subject_search(delegate.page):
808793 path = '/search/subjects'
809794
810795 def GET (self ):
811- get_results = functools .partial (self .get_results , query_label = 'SUBJECT_SEARCH' )
796+ get_results = functools .partial (
797+ self .get_results , request_label = 'SUBJECT_SEARCH'
798+ )
812799 return render_template ('search/subjects' , get_results )
813800
814801 def get_results (
815802 self ,
816803 q ,
817- query_label : Literal ['SUBJECT_SEARCH' , 'SUBJECT_SEARCH_API' ],
804+ request_label : Literal ['SUBJECT_SEARCH' , 'SUBJECT_SEARCH_API' ],
818805 offset = 0 ,
819806 limit = 100 ,
820807 ):
@@ -824,7 +811,7 @@ def get_results(
824811 offset = offset ,
825812 rows = limit ,
826813 sort = 'work_count desc' ,
827- query_label = query_label ,
814+ request_label = request_label ,
828815 )
829816
830817 return response
@@ -842,7 +829,7 @@ def GET(self):
842829
843830 response = self .get_results (
844831 i .q ,
845- query_label = 'SUBJECT_SEARCH_API' ,
832+ request_label = 'SUBJECT_SEARCH_API' ,
846833 offset = offset ,
847834 limit = limit ,
848835 )
@@ -861,13 +848,13 @@ class author_search(delegate.page):
861848 path = '/search/authors'
862849
863850 def GET (self ):
864- get_results = functools .partial (self .get_results , query_label = 'AUTHOR_SEARCH' )
851+ get_results = functools .partial (self .get_results , request_label = 'AUTHOR_SEARCH' )
865852 return render_template ('search/authors' , get_results )
866853
867854 def get_results (
868855 self ,
869856 q ,
870- query_label : Literal ['AUTHOR_SEARCH' , 'AUTHOR_SEARCH_API' ],
857+ request_label : Literal ['AUTHOR_SEARCH' , 'AUTHOR_SEARCH_API' ],
871858 offset = 0 ,
872859 limit = 100 ,
873860 fields = '*' ,
@@ -880,7 +867,7 @@ def get_results(
880867 rows = limit ,
881868 fields = fields ,
882869 sort = sort ,
883- query_label = query_label ,
870+ request_label = request_label ,
884871 )
885872
886873 return resp
@@ -898,7 +885,7 @@ def GET(self):
898885
899886 response = self .get_results (
900887 i .q ,
901- query_label = 'AUTHOR_SEARCH_API' ,
888+ request_label = 'AUTHOR_SEARCH_API' ,
902889 offset = offset ,
903890 limit = limit ,
904891 fields = i .fields ,
@@ -968,7 +955,7 @@ def work_search(
968955 fields : str = '*' ,
969956 facet : bool = True ,
970957 spellcheck_count : int | None = None ,
971- query_label : QueryLabel = 'UNLABELLED' ,
958+ request_label : SolrRequestLabel = 'UNLABELLED' ,
972959) -> dict :
973960 """
974961 :param sort: key of SORTS dict at the top of this file
@@ -991,7 +978,7 @@ def work_search(
991978 fields = fields ,
992979 facet = facet ,
993980 spellcheck_count = spellcheck_count ,
994- query_label = query_label ,
981+ request_label = request_label ,
995982 )
996983 response = resp .raw_resp ['response' ]
997984
@@ -1065,7 +1052,7 @@ def GET(self):
10651052 # so disable it. This makes it much faster.
10661053 facet = False ,
10671054 spellcheck_count = spellcheck_count ,
1068- query_label = 'BOOK_SEARCH_API' ,
1055+ request_label = 'BOOK_SEARCH_API' ,
10691056 )
10701057 response ['documentation_url' ] = "https://openlibrary.org/dev/docs/api/search"
10711058 response ['q' ] = q
0 commit comments