@@ -7,7 +7,7 @@ xquery version "3.1";
77 : Since a barear token is required please set it in cache or store in to module/data/adsabs.xml .
88 :
99 : Prefer the use of getter to retrieve result's content or use the following namespace to work directly on ads records:
10- : declare namespace ads="http ://ads.harvard.edu/schema/abs/1.1/abstracts";
10+ : declare namespace ads="https ://ads.harvard.edu/schema/abs/1.1/abstracts";
1111 :
1212 : Note: get-record and get-record functions always cache retrieved records
1313 :
@@ -18,7 +18,7 @@ import module namespace http = "http://expath.org/ns/http-client";
1818import module namespace test="http://exist-db.org/xquery/xqsuite" at "resource:org/exist/xquery/lib/xqsuite/xqsuite.xql" ;
1919
2020
21- declare namespace ads="http ://ads.harvard.edu/schema/abs/1.1/abstracts" ;
21+ declare namespace ads="https ://ads.harvard.edu/schema/abs/1.1/abstracts" ;
2222
2323(: define ads cache collection path to store documents :)
2424declare variable $adsabs:collection-uri := "/db/ads/records/" ;
@@ -94,13 +94,16 @@ declare function adsabs:query( $query-url as xs:string, $query-payload as xs:str
9494 return
9595 if ($response-head/@status = ("200" ,"404" ))
9696 then
97+ (: let $log := util:log("info", "response from ads : ") :)
9798 let $json := util:binary-to-string ($response-body)
99+ (: let $log := util:log("info", $json ) :)
98100 let $cache := cache:put ($adsabs:expirable-cache-name, $key, $json) (: always cache last result :)
99101 return $json
100102 else
101103 (util:log ("error" ,replace (serialize ($request), $adsabs:token, "XXXXXXXX" )),
102104 util:log ("error" ,serialize ($response-head)),
103105 util:log ("error" ,serialize ($response-body)),
106+ util:log ("error" ,util:base64-decode (serialize ($response-body))),
104107(: util:log("error", "token is " || $adsabs:token),:)
105108 fn:error (xs:QName ("adsabs:bad-request-1" ), $response-head/@status ||":" || $response-head/@message))
106109 else
@@ -179,10 +182,12 @@ declare function adsabs:get-records($bibcodes as xs:string*, $use-cache as xs:bo
179182
180183 (: TODO perform a load test to check limit of returned records 2000 ? :)
181184 let $new-records := if ( exists ($bibcodes-todo) ) then
185+ let $log := util:log ("info" , "requesting bibcodes : " || string-join ($bibcodes-todo ! concat ("" " ,.,"" " ), ", " ) )
182186 let $quoted-bibcodes-todo := for $b in $bibcodes-todo return "" " ||$b||"" "
183187 let $payload := '{"bibcode": [' || string-join ($quoted-bibcodes-todo, ", " ) || "]}"
184188 let $json-resp := adsabs:query ("/export/refabsxml" ,$payload)
185189 let $json-resp-export := parse-json ($json-resp)?export
190+ (: let $log := util:log("info", "xml response is : " || $json-resp-export ) :)
186191 return
187192 parse-xml ($json-resp-export)//ads:record
188193 else
@@ -192,7 +197,17 @@ declare function adsabs:get-records($bibcodes as xs:string*, $use-cache as xs:bo
192197
193198 let $bibcodes-not-done := $bibcodes-todo[not (.=$new-records/ads:bibcode)]
194199 let $bibcodes-not-requested := $new-records/ads:bibcode[not (.=$bibcodes-todo)]
195- let $log := if (exists ($bibcodes-not-done)) then util:log ("warn" , "Missmatch between request and response: absent bibcodes : (" " || string-join ($bibcodes-not-done, "" , " " ) || "" )" || " unrequested bibcodes : (" " || string-join ($bibcodes-not-requested, "" , " " ) || "" )" ) else ()
200+ let $log := if (exists ($bibcodes-not-done))
201+ then
202+ (
203+ util:log ("warn" , "Missmatch between request and response:" )
204+ ,util:log ("warn" , "absent bibcodes : " || string-join ($bibcodes-not-done ! concat ("" " ,.,"" " ), ", " ) )
205+ ,util:log ("warn" , "unrequested bibcodes : " || string-join ($bibcodes-not-requested ! concat ("" " ,.,"" " ), ", " ))
206+ ,util:log ("warn" , "new records :" )
207+ ,util:log ("warn" , $new-records )
208+ )
209+ else
210+ ()
196211
197212 return
198213 ($new-records,$cached-records)
@@ -248,7 +263,7 @@ declare function adsabs:library($name-or-id)
248263};
249264declare function adsabs:library ($name-or-id, $use-cache as xs:boolean)
250265{
251- let $id := adsabs:get-libraries ()?* ?*[?name=$name-or-id or ?id=$name-or-id]?id
266+ let $id := adsabs:get-libraries ()?libraries ?*[?name=$name-or-id or ?id=$name-or-id]?id
252267 return parse-json (adsabs:query ("/biblib/libraries/" ||$id, (), $use-cache))
253268};
254269declare function adsabs:library-id ($name){
@@ -266,7 +281,7 @@ declare function adsabs:library-get-permissions($name-or-id)
266281
267282declare function adsabs:library-get-permissions ($name-or-id, $use-cache as xs:boolean)
268283{
269- let $id := adsabs:get-libraries ()?* ?*[?name=$name-or-id or ?id=$name-or-id]?id
284+ let $id := adsabs:get-libraries ()?libraries ?*[?name=$name-or-id or ?id=$name-or-id]?id
270285 return parse-json (adsabs:query ("/biblib/permissions/" ||$id, (), $use-cache))
271286};
272287
@@ -295,7 +310,7 @@ declare function adsabs:library-get-bibcodes($name-or-id, $use-cache as xs:boole
295310
296311declare function adsabs:library-get-search-expr ($name-or-id)
297312{
298- let $id := adsabs:get-libraries ()?* ?*[?name=$name-or-id or ?id=$name-or-id]?id
313+ let $id := adsabs:get-libraries ()?libraries ?*[?name=$name-or-id or ?id=$name-or-id]?id
299314 return "docs(library/" ||$id||")"
300315};
301316
@@ -334,29 +349,33 @@ declare function adsabs:library-clear($name-or-id){
334349};
335350
336351declare %private function adsabs:library-add-or-remove ($name-or-id, $bibcodes, $action){
337- let $bibcodes := $bibcodes[.!= '' ]
352+ let $bibcodes:= $bibcodes[string-length (.)> 0 ]
338353 return
339354 if (exists ($bibcodes)) then
340355 let $quoted-bibcodes-todo := for $b in $bibcodes return "" " ||$b||"" "
341356 let $payload := '{"action":"' ||$action||'" ,"bibcode": [' || string-join ($quoted-bibcodes-todo, ", " ) || "]}"
342- let $id := adsabs:get-libraries ()?* ?*[?name=$name-or-id or ?id=$name-or-id]?id
357+ let $id := adsabs:get-libraries ()?libraries ?*[?name=$name-or-id or ?id=$name-or-id]?id
343358 return
344359 parse-json (adsabs:query ("/biblib/documents/" ||$id, $payload, false ()))
345360 else
346361 util:log ("info" , "Skipping action on library " || $name-or-id || ". no bibcode provided for " ||$action)
347362};
348363
349364declare function adsabs:search-bibcodes ($query) as xs:string*{
350- adsabs:search ($query, "bibcode" )?response?docs?*?bibcode
365+ adsabs:search-bibcodes ($query, true ())
366+ };
367+
368+ declare function adsabs:search-bibcodes ($query, $cache) as xs:string*{
369+ adsabs:search ($query, "bibcode" , $cache)?response?docs?*?bibcode
351370};
352371
353372(: Search without using cache :)
354- declare function adsabs:search ($query as xs:string, $fl as xs:string* )
373+ declare function adsabs:search ($query as xs:string, $fl as xs:string? )
355374{
356375 adsabs:search ($query, $fl, true ())
357376};
358377
359- declare function adsabs:search ($query as xs:string, $fl as xs:string* , $use-cache as xs:boolean)
378+ declare function adsabs:search ($query as xs:string, $fl as xs:string? , $use-cache as xs:boolean)
360379{
361380 parse-json (
362381 adsabs:query ("/search/query?q=" ||encode-for-uri ($query)
@@ -367,10 +386,12 @@ declare function adsabs:search($query as xs:string, $fl as xs:string*, $use-cach
367386};
368387
369388(:~
370- : Give access to the solr endpoint.
371- : default output format is defined to xml.
389+ : Query ADS using the full SOLR interface
390+ : @param $params map of query params ( default output format is defined to wt=xml )
391+ : @param $use-cache true use cache to retrieve last result if any else skip flag
392+ : @return true if refereed, false else
372393 :)
373- declare function adsabs:search-solr ($params as map (*), $use-cache as xs:boolean)
394+ declare function adsabs:search-map ($params as map (*), $use-cache as xs:boolean)
374395{
375396 let $params-keys := map:keys ($params)
376397 let $defaults := (
0 commit comments