66import re
77import sys
88
9- import requests
109import web
1110
12- from infogami import config
1311from infogami .utils import stats
1412from infogami .utils .delegate import register_exception
15- from openlibrary .api import OpenLibrary # noqa: F401 side effects may be needed
1613from openlibrary .core import helpers , ia
1714from openlibrary .plugins .books import dynlinks
1815
@@ -21,39 +18,6 @@ def key_to_olid(key):
2118 return key .split ('/' )[- 1 ]
2219
2320
24- def ol_query (name , value ):
25- query = {
26- 'type' : '/type/edition' ,
27- name : value ,
28- }
29- if keys := web .ctx .site .things (query ):
30- return keys [0 ]
31-
32-
33- def get_solr_select_url ():
34- c = config .get ("plugin_worksearch" )
35- base_url = c and c .get ('solr_base_url' )
36- return base_url and (base_url + "/select" )
37-
38-
39- def get_work_iaids (wkey ):
40- # wid = wkey.split('/')[2]
41- solr_select_url = get_solr_select_url ()
42- filter = 'ia'
43- q = 'key:' + wkey
44- stats .begin ('solr' , url = wkey )
45- solr_select = (
46- solr_select_url
47- + f"?version=2.2&q.op=AND&q={ q } &rows=10&fl={ filter } &qt=standard&wt=json&fq=type:work"
48- )
49- reply = requests .get (solr_select ).json ()
50- stats .end ()
51- print (reply )
52- if reply ['response' ]['numFound' ] == 0 :
53- return []
54- return reply ["response" ]['docs' ][0 ].get (filter , [])
55-
56-
5721def get_solr_fields_for_works (
5822 field : str ,
5923 wkeys : list [str ],
@@ -65,42 +29,6 @@ def get_solr_fields_for_works(
6529 return {doc ['key' ]: doc .get (field , [])[:clip_limit ] for doc in docs }
6630
6731
68- def get_eids_for_wids (wids ):
69- """To support testing by passing in a list of work-ids - map each to
70- it's first edition ID"""
71- solr_select_url = get_solr_select_url ()
72- filter = 'edition_key'
73- q = '+OR+' .join (wids )
74- solr_select = (
75- solr_select_url
76- + f"?version=2.2&q.op=AND&q={ q } &rows=10&fl=key,{ filter } &qt=standard&wt=json&fq=type:work"
77- )
78- reply = requests .get (solr_select ).json ()
79- if reply ['response' ]['numFound' ] == 0 :
80- return []
81- rows = reply ['response' ]['docs' ]
82- result = {r ['key' ]: r [filter ][0 ] for r in rows if len (r .get (filter , []))}
83- return result
84-
85-
86- # Not yet used. Solr editions aren't up-to-date (6/2011)
87- def get_solr_edition_records (iaids ):
88- solr_select_url = get_solr_select_url ()
89- filter = 'title'
90- q = '+OR+' .join ('ia:' + id for id in iaids )
91- solr_select = (
92- solr_select_url
93- + f"?version=2.2&q.op=AND&q={ q } &rows=10&fl=key,{ filter } &qt=standard&wt=json"
94- )
95- reply = requests .get (solr_select ).json ()
96- if reply ['response' ]['numFound' ] == 0 :
97- return []
98- rows = reply ['response' ]['docs' ]
99- return rows
100- result = {r ['key' ]: r [filter ][0 ] for r in rows if len (r .get (filter , []))}
101- return result
102-
103-
10432class ReadProcessor :
10533 def __init__ (self , options ):
10634 self .options = options
0 commit comments