-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,66 @@ | ||
import logging | ||
from datetime import datetime | ||
from types import MappingProxyType | ||
from typing import ClassVar | ||
|
||
from openlibrary.plugins.worksearch.schemes import SearchScheme | ||
|
||
logger = logging.getLogger("openlibrary.worksearch") | ||
|
||
|
||
# Kind of mostly a stub for now since you can't really search editions | ||
# directly, but it's still useful for somethings (e.g., editions have a custom | ||
# directly, but it's still useful for somethings (eg editions have a custom | ||
# sort logic). | ||
class EditionSearchScheme(SearchScheme): | ||
universe = frozenset(['type:work']) | ||
universe = ['type:work'] | ||
all_fields = { | ||
"key", | ||
"title", | ||
"subtitle", | ||
"alternative_title", | ||
"alternative_subtitle", | ||
"cover_i", | ||
"ebook_access", | ||
"publish_date", | ||
"lccn", | ||
"ia", | ||
"isbn", | ||
"publisher", | ||
"has_fulltext", | ||
"title_suggest", | ||
"publish_year", | ||
"language", | ||
"publisher_facet", | ||
} | ||
facet_fields: set[str] = set() | ||
field_name_map = { | ||
'publishers': 'publisher', | ||
'subtitle': 'alternative_subtitle', | ||
'title': 'alternative_title', | ||
# "Private" fields | ||
# This is private because we'll change it to a multi-valued field instead of a | ||
# plain string at the next opportunity, which will make it much more usable. | ||
'_ia_collection': 'ia_collection_s', | ||
} | ||
sorts = { | ||
'old': 'def(publish_year, 9999) asc', | ||
'new': 'publish_year desc', | ||
'title': 'title_sort asc', | ||
# Ebook access | ||
'ebook_access': 'ebook_access desc', | ||
'ebook_access asc': 'ebook_access asc', | ||
'ebook_access desc': 'ebook_access desc', | ||
# Key | ||
'key': 'key asc', | ||
'key asc': 'key asc', | ||
'key desc': 'key desc', | ||
# Random | ||
'random': 'random_1 asc', | ||
'random asc': 'random_1 asc', | ||
'random desc': 'random_1 desc', | ||
'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', | ||
'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', | ||
} | ||
default_fetched_fields: set[str] = set() | ||
facet_rewrites = {} | ||
|
||
all_fields = frozenset( | ||
[ | ||
"key", | ||
"title", | ||
"subtitle", | ||
"alternative_title", | ||
"alternative_subtitle", | ||
"cover_i", | ||
"ebook_access", | ||
"publish_date", | ||
"lccn", | ||
"ia", | ||
"isbn", | ||
"publisher", | ||
"has_fulltext", | ||
"title_suggest", | ||
"publish_year", | ||
"language", | ||
"publisher_facet", | ||
] | ||
) | ||
|
||
facet_fields: ClassVar[set[str]] = frozenset() | ||
|
||
field_name_map: ClassVar[dict[str, str]] = dict( | ||
MappingProxyType( | ||
{ | ||
'publishers': 'publisher', | ||
'subtitle': 'alternative_subtitle', | ||
'title': 'alternative_title', | ||
# "Private" fields | ||
# This is private because we'll change it to a multi-valued field instead of a | ||
# plain string at the next opportunity, which will make it much more usable. | ||
'_ia_collection': 'ia_collection_s', | ||
} | ||
) | ||
) | ||
|
||
sorts: ClassVar[dict[str, str]] = dict( | ||
MappingProxyType( | ||
{ | ||
'old': 'def(publish_year, 9999) asc', | ||
'new': 'publish_year desc', | ||
'title': 'title_sort asc', | ||
'ebook_access': 'ebook_access desc', | ||
'ebook_access asc': 'ebook_access asc', | ||
'ebook_access desc': 'ebook_access desc', | ||
'key': 'key asc', | ||
'key asc': 'key asc', | ||
'key desc': 'key desc', | ||
'random': 'random_1 asc', | ||
'random asc': 'random_1 asc', | ||
'random desc': 'random_1 desc', | ||
'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc', | ||
'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc', | ||
} | ||
) | ||
) | ||
|
||
default_fetched_fields: ClassVar[frozenset] = frozenset() | ||
facet_rewrites: ClassVar[dict[tuple[str, str], str]] = {} | ||
|
||
def is_search_field(self, field: str) -> bool: | ||
"""Check if the field is a valid search field, including fields starting with 'id_'.""" | ||
def is_search_field(self, field: str): | ||
return super().is_search_field(field) or field.startswith('id_') |