Skip to content

Commit

Permalink
ignore empty bibcodes and add search-solr function
Browse files Browse the repository at this point in the history
  • Loading branch information
gmella committed Sep 20, 2023
1 parent 3ac5d1d commit fcc54c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
30 changes: 17 additions & 13 deletions content/adsabs.xql
Original file line number Diff line number Diff line change
Expand Up @@ -334,28 +334,29 @@ declare function adsabs:library-clear($name-or-id){
};

declare %private function adsabs:library-add-or-remove($name-or-id, $bibcodes, $action){
if (exists($bibcodes)) then
let $quoted-bibcodes-todo := for $b in $bibcodes return """||$b||"""
let $payload := '{"action":"'||$action||'" ,"bibcode": [' || string-join($quoted-bibcodes-todo, ", ") || "]}"
let $id := adsabs:get-libraries()?*?*[?name=$name-or-id or ?id=$name-or-id]?id
return
parse-json(adsabs:query("/biblib/documents/"||$id, $payload, false()))
else
util:log("info", "Skipping action on library " || $name-or-id || ". no bibcode provided for "||$action)

let $bibcodes := $bibcodes[.!='']
return
if (exists($bibcodes)) then
let $quoted-bibcodes-todo := for $b in $bibcodes return """||$b||"""
let $payload := '{"action":"'||$action||'" ,"bibcode": [' || string-join($quoted-bibcodes-todo, ", ") || "]}"
let $id := adsabs:get-libraries()?*?*[?name=$name-or-id or ?id=$name-or-id]?id
return
parse-json(adsabs:query("/biblib/documents/"||$id, $payload, false()))
else
util:log("info", "Skipping action on library " || $name-or-id || ". no bibcode provided for "||$action)
};

declare function adsabs:search-bibcodes($query) as xs:string*{
adsabs:search($query, "bibcode")?response?docs?*?bibcode
};

(: Search without using cache :)
declare function adsabs:search($query as xs:string, $fl as xs:string?)
declare function adsabs:search($query as xs:string, $fl as xs:string*)
{
adsabs:search($query, $fl, true())
};

declare function adsabs:search($query as xs:string, $fl as xs:string?, $use-cache as xs:boolean)
declare function adsabs:search($query as xs:string, $fl as xs:string*, $use-cache as xs:boolean)
{
parse-json(
adsabs:query("/search/query?q="||encode-for-uri($query)
Expand All @@ -365,7 +366,11 @@ declare function adsabs:search($query as xs:string, $fl as xs:string?, $use-cach
)
};

declare function adsabs:search-map($params as map(*), $use-cache as xs:boolean)
(:~
: Give access to the solr endpoint.
: default output format is defined to xml.
:)
declare function adsabs:search-solr($params as map(*), $use-cache as xs:boolean)
{
let $params-keys := map:keys($params)
let $defaults := (
Expand All @@ -381,7 +386,6 @@ declare function adsabs:search-map($params as map(*), $use-cache as xs:boolean)
};



(: --- GETTER functions :)

declare %private function adsabs:ignore-bad-refereed-bibcode($bibcodes as xs:string*) {
Expand Down
3 changes: 3 additions & 0 deletions repo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<change version="0.45.0">
<ul xmlns="">
<li>dateutil : add timestampToDateTime() to convert seconds since the epoch (1970-01-01 UTC) to a datetime.</li>
<li>jmmc-simbad: fix bug / bad query in resolv-by-coords funtion.</li>
<li>adsabs : add search-solr function.</li>
<li>adsabs : ignore empty bibcodes in library management (avoid 500 error on ADS servers).</li>
</ul>
</change>
<change version="0.44.0">
Expand Down

0 comments on commit fcc54c9

Please sign in to comment.