Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Translations template for Open Library.
# Copyright (C) 2025 Internet Archive
# Copyright (C) 2026 Internet Archive
# This file is distributed under the same license as the Open Library
# project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2025.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2026.
#
#, fuzzy
msgid ""
Expand Down
4 changes: 1 addition & 3 deletions openlibrary/plugins/worksearch/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,7 @@ def get_doc(doc: SolrDocument):
url=f"{doc['key']}/{urlsafe(doc['title'])}",
edition_count=doc['edition_count'],
ia=doc.get('ia', []),
collections=(
doc['ia_collection_s'].split(';') if doc.get('ia_collection_s') else []
),
collections=(doc.get('ia_collection') or []),
has_fulltext=doc.get('has_fulltext', False),
public_scan=doc.get('public_scan_b', bool(doc.get('ia'))),
lending_edition=doc.get('lending_edition_s', None),
Expand Down
5 changes: 1 addition & 4 deletions openlibrary/plugins/worksearch/schemes/editions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class EditionSearchScheme(SearchScheme):
'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',
'_ia_collection': 'ia_collection',
}
)
sorts = MappingProxyType(
Expand Down
26 changes: 2 additions & 24 deletions openlibrary/plugins/worksearch/schemes/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ class WorkSearchScheme(SearchScheme):
'work_subtitle': 'subtitle',
'work_title': 'title',
'trending': 'trending_z_score',
# "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',
'_ia_collection': 'ia_collection',
}
)
sorts = MappingProxyType(
Expand Down Expand Up @@ -211,7 +208,7 @@ class WorkSearchScheme(SearchScheme):
'lending_edition_s',
'lending_identifier_s',
'language',
'ia_collection_s',
'ia_collection',
# FIXME: These should be fetched from book_providers, but can't cause circular
# dep
'id_project_gutenberg',
Expand Down Expand Up @@ -278,8 +275,6 @@ def transform_user_query(
lcc_transform(node)
if node.name in ('dcc', 'dcc_sort'):
ddc_transform(node)
if node.name == 'ia_collection_s':
ia_collection_s_transform(node)

if not has_search_fields:
# If there are no search fields, maybe we want just an isbn?
Expand Down Expand Up @@ -737,23 +732,6 @@ def isbn_transform(sf: luqum.tree.SearchField):
logger.warning(f"Unexpected isbn SearchField value type: {type(field_val)}")


def ia_collection_s_transform(sf: luqum.tree.SearchField):
"""
Because this field is not a multi-valued field in solr, but a simple ;-separate
string, we have to do searches like this for now.
"""
val = sf.children[0]
if isinstance(val, luqum.tree.Word):
if val.value.startswith('*'):
val.value = '*' + val.value
if val.value.endswith('*'):
val.value += '*'
else:
logger.warning(
f"Unexpected ia_collection_s SearchField value type: {type(val)}"
)


def has_solr_editions_enabled():
if 'pytest' in sys.modules:
return True
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/plugins/worksearch/subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def get_subject(
"cover_edition_key",
"has_fulltext",
"subject",
"ia_collection_s",
"ia_collection",
"public_scan_b",
"lending_edition_s",
"lending_identifier_s",
Expand Down Expand Up @@ -419,7 +419,7 @@ def work_wrapper(w: dict) -> web.storage:
These docs are weird :/ We should be using more standardized results
across our search APIs, but that would be a big breaking change.
"""
ia_collection = w.get('ia_collection_s', '').split(';')
ia_collection = w.get('ia_collection') or []
return web.storage(
key=w['key'],
title=w["title"],
Expand Down
1 change: 0 additions & 1 deletion openlibrary/solr/solr_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class SolrDocument(TypedDict):
public_scan_b: Optional[bool]
printdisabled_s: Optional[str]
lending_edition_s: Optional[str]
ia_collection_s: Optional[str]
ebook_count_i: Optional[int]

# fmt: on
1 change: 0 additions & 1 deletion openlibrary/solr/types_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
'public_scan_b': 'Optional[bool]',
'printdisabled_s': 'Optional[str]',
'lending_edition_s': 'Optional[str]',
'ia_collection_s': 'Optional[str]',
'ebook_count_i': 'Optional[int]',
}

Expand Down
4 changes: 0 additions & 4 deletions openlibrary/solr/updater/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,6 @@ def ia(self) -> list[str]:
def ia_collection(self) -> list[str]:
return sorted(uniq(c for e in self._solr_editions for c in e.ia_collection))

@property
def ia_collection_s(self) -> str:
return ';'.join(self.ia_collection)

@cached_property
def _ia_editions(self) -> list[EditionSolrBuilder]:
def get_ia_sorting_key(ed: EditionSolrBuilder) -> tuple[int, str]:
Expand Down
16 changes: 10 additions & 6 deletions openlibrary/tests/solr/updater/test_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_with_one_lending_edition(self):
assert d.printdisabled_s is None
assert d.lending_edition_s == 'OL1M'
assert d.ia == ['foo00bar']
assert sss(d.ia_collection_s) == sss("americana;inlibrary")
assert sorted(d.ia_collection) == sorted(["americana", "inlibrary"])
assert d.edition_count == 1
assert d.ebook_count_i == 1

Expand All @@ -222,7 +222,9 @@ def test_with_two_lending_editions(self):
assert d.printdisabled_s is None
assert d.lending_edition_s == 'OL1M'
assert sorted(d.ia) == ['foo01bar', 'foo02bar']
assert sss(d.ia_collection_s) == sss("inlibrary;americana;internetarchivebooks")
assert sorted(d.ia_collection) == sorted(
["inlibrary", "americana", "internetarchivebooks"]
)
assert d.edition_count == 2
assert d.ebook_count_i == 2

Expand All @@ -238,7 +240,7 @@ def test_with_one_inlibrary_edition(self):
assert d.printdisabled_s == 'OL1M'
assert d.lending_edition_s == 'OL1M'
assert d.ia == ['foo00bar']
assert sss(d.ia_collection_s) == sss("printdisabled;inlibrary")
assert sorted(d.ia_collection) == sorted(["printdisabled", "inlibrary"])
assert d.edition_count == 1
assert d.ebook_count_i == 1

Expand All @@ -254,7 +256,7 @@ def test_with_one_printdisabled_edition(self):
assert d.printdisabled_s == 'OL1M'
assert d.lending_edition_s is None
assert d.ia == ['foo00bar']
assert sss(d.ia_collection_s) == sss("printdisabled;americana")
assert sorted(d.ia_collection) == sorted(["printdisabled", "americana"])
assert d.edition_count == 1
assert d.ebook_count_i == 1

Expand Down Expand Up @@ -295,7 +297,9 @@ def test_with_multiple_editions(self):
assert d.printdisabled_s == 'OL4M'
assert d.lending_edition_s == 'OL2M'
assert sorted(d.ia) == ['foo00bar', 'foo01bar', 'foo02bar']
assert sss(d.ia_collection_s) == sss("americana;inlibrary;printdisabled")
assert sorted(d.ia_collection) == sorted(
["americana", "inlibrary", "printdisabled"]
)

assert d.edition_count == 4
assert d.ebook_count_i == 3
Expand Down Expand Up @@ -544,4 +548,4 @@ def test_excludes_fav_ia_collections(self):
},
)

assert wsb.ia_collection_s == "americanlibraries;blah"
assert sorted(wsb.ia_collection) == sorted(["americanlibraries", "blah"])