Skip to content

Commit f5cd3c9

Browse files
committed
Add last_modified, seed_count fields to solr for lists
1 parent a267d95 commit f5cd3c9

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
@@ -266,6 +266,10 @@
266266
<!-- additional fields used by documents of type subject -->
267267
<field name="subject_type" type="string" indexed="true" stored="true"/>
268268

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

openlibrary/plugins/worksearch/code.py

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

708708
def GET(self): # referenced subject_search
709-
req = ListSearchRequest.from_web_input(web.input(api='new'))
709+
req = ListSearchRequest.from_web_input(web.input(api='next'))
710710
# Can't set fields when rendering html
711711
req.fields = 'key'
712712
resp = self.get_results(req)

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
@@ -120,6 +122,8 @@ class SolrDocument(TypedDict):
120122
top_work: Optional[str]
121123
top_subjects: Optional[list[str]]
122124
subject_type: Optional[str]
125+
last_modified: Optional[str]
126+
seed_count: Optional[int]
123127
public_scan_b: Optional[bool]
124128
printdisabled_s: Optional[str]
125129
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)