Skip to content

Commit

Permalink
Make has_fulltext user pd-status aware
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrini committed Dec 14, 2022
1 parent bc6adf0 commit 14f8029
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion openlibrary/plugins/worksearch/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def run_solr_query(
if param.get(field) == value:
if field in facet_params:
facet_params.remove(field)
params.append(('fq', rewrite))
params.append(('fq', rewrite() if callable(rewrite) else rewrite))

for field in facet_params:
if field == 'author_facet':
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/worksearch/schemes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SearchScheme:
# Default
default_fetched_fields: set[str]
# Fields that should be rewritten
facet_rewrites: dict[tuple[str, str], str]
facet_rewrites: dict[tuple[str, str], Union[str, Callable[[], str]]]

def is_search_field(self, field: str):
return field in self.all_fields or field in self.field_name_map
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/plugins/worksearch/schemes/authors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
import logging
from typing import Callable, Union

from openlibrary.plugins.worksearch.schemes import SearchScheme

Expand Down Expand Up @@ -38,7 +39,7 @@ class AuthorSearchScheme(SearchScheme):
'top_subjects',
'work_count',
}
facet_rewrites: dict[tuple[str, str], str] = {}
facet_rewrites: dict[tuple[str, str], Union[str, Callable[[], str]]] = {}

def q_to_solr_params(
self,
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/plugins/worksearch/schemes/subjects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
import logging
from typing import Callable, Union

from openlibrary.plugins.worksearch.schemes import SearchScheme

Expand Down Expand Up @@ -31,7 +32,7 @@ class SubjectSearchScheme(SearchScheme):
'subject_type',
'work_count',
}
facet_rewrites: dict[tuple[str, str], str] = {}
facet_rewrites: dict[tuple[str, str], Union[str, Callable[[], str]]] = {}

def q_to_solr_params(
self,
Expand Down
15 changes: 13 additions & 2 deletions openlibrary/plugins/worksearch/schemes/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,14 @@ class WorkSearchScheme(SearchScheme):
('public_scan', 'false'): '-ebook_access:public',
('print_disabled', 'true'): 'ebook_access:printdisabled',
('print_disabled', 'false'): '-ebook_access:printdisabled',
('has_fulltext', 'true'): 'ebook_access:[printdisabled TO *]',
('has_fulltext', 'false'): 'ebook_access:[* TO printdisabled}',
(
'has_fulltext',
'true',
): lambda: f'ebook_access:[{get_fulltext_min()} TO *]',
(
'has_fulltext',
'false',
): lambda: f'ebook_access:[* TO {get_fulltext_min()}}}',
}

def is_search_field(self, field: str):
Expand Down Expand Up @@ -552,3 +558,8 @@ def read_cookie():
return cookie_value == 'true'

return True


def get_fulltext_min():
is_printdisabled = web.cookies().get('pd', False)
return 'printdisabled' if is_printdisabled else 'borrowable'

0 comments on commit 14f8029

Please sign in to comment.