Skip to content

Commit 7084a3f

Browse files
authored
Merge pull request internetarchive#11179 from cdrini/11177/feature/new-solr-list-fields
Add last_modified, seed_count fields to solr for lists
2 parents 77f73b1 + f5cd3c9 commit 7084a3f

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

conf/solr/conf/managed-schema.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@
267267
<!-- additional fields used by documents of type subject -->
268268
<field name="subject_type" type="string" indexed="true" stored="true"/>
269269

270+
<!-- fields used by documents of type list -->
271+
<field name="last_modified" type="pdate" indexed="true" stored="true"/>
272+
<field name="seed_count" type="pint" indexed="true" stored="true"/>
273+
270274
<!-- dynamic fields -->
271275
<dynamicField name="id_*" type="string" indexed="true" stored="true" multiValued="true"/>
272276

openlibrary/plugins/worksearch/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ class list_search(delegate.page):
734734
path = '/search/lists'
735735

736736
def GET(self): # referenced subject_search
737-
req = ListSearchRequest.from_web_input(web.input(api='new'))
737+
req = ListSearchRequest.from_web_input(web.input(api='next'))
738738
# Can't set fields when rendering html
739739
req.fields = 'key'
740740
resp = self.get_results(req, 'LIST_SEARCH')

openlibrary/plugins/worksearch/schemes/lists.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class ListSearchScheme(SearchScheme):
2626
'place_key',
2727
'time',
2828
'time_key',
29+
'last_modified',
30+
'seed_count',
2931
}
3032
)
3133

@@ -36,7 +38,13 @@ class ListSearchScheme(SearchScheme):
3638
field_name_map = MappingProxyType({})
3739
sorts = MappingProxyType(
3840
{
39-
'name asc': 'name asc', # sort alphabetically
41+
'name asc': 'name asc',
42+
'last_modified': 'last_modified desc',
43+
'last_modified asc': 'last_modified asc',
44+
'last_modified desc': 'last_modified desc',
45+
'seed_count': 'seed_count desc',
46+
'seed_count asc': 'seed_count asc',
47+
'seed_count desc': 'seed_count desc',
4048
# Random (kept from SubjectSearchScheme)
4149
'random': 'random_1 asc',
4250
'random asc': 'random_1 asc',

openlibrary/solr/solr_types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# This file is auto-generated by types_generator.py
2+
# To regenerate:
3+
# python openlibrary/solr/types_generator.py > openlibrary/solr/solr_types.py
24
# fmt: off
35
# ruff: noqa: UP045
46
from typing import Literal, Optional, TypedDict
@@ -121,6 +123,8 @@ class SolrDocument(TypedDict):
121123
top_work: Optional[str]
122124
top_subjects: Optional[list[str]]
123125
subject_type: Optional[str]
126+
last_modified: Optional[str]
127+
seed_count: Optional[int]
124128
public_scan_b: Optional[bool]
125129
printdisabled_s: Optional[str]
126130
lending_edition_s: Optional[str]

openlibrary/solr/types_generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def generate():
3131
typ = field.get('type')
3232
multivalued = field.get('multiValued') == 'true'
3333
type_map = {
34+
'pdate': 'str',
3435
'pint': 'int',
3536
'string': 'str',
3637
'text_en_splitting': 'str',
@@ -81,6 +82,8 @@ def generate():
8182

8283
body = '\n'.join(python_fields)
8384
python = f"""# This file is auto-generated by types_generator.py
85+
# To regenerate:
86+
# python openlibrary/solr/types_generator.py > openlibrary/solr/solr_types.py
8487
# fmt: off
8588
# ruff: noqa: UP045
8689
from typing import Literal, Optional, TypedDict

openlibrary/solr/updater/list.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
from collections import defaultdict
3+
from functools import cached_property
34
from typing import cast
45

56
import httpx
@@ -106,7 +107,7 @@ def type(self) -> str:
106107
def name(self) -> str | None:
107108
return self._list.get('name')
108109

109-
@property
110+
@cached_property
110111
def seed(self) -> list[str]:
111112
return [
112113
(
@@ -116,3 +117,12 @@ def seed(self) -> list[str]:
116117
)
117118
for seed in self._list.get('seeds', [])
118119
]
120+
121+
@property
122+
def last_modified(self) -> str:
123+
# Solr expects UTC ISO 8601 with 'Z' suffix, e.g. 2024-12-09T12:57:14.074200Z
124+
return self._list['last_modified']['value'] + 'Z'
125+
126+
@property
127+
def seed_count(self) -> int:
128+
return len(self.seed)

0 commit comments

Comments
 (0)