lib/qa/authorities/getty.rb in qa-0.4.1 vs lib/qa/authorities/getty.rb in qa-0.4.2

- old
+ new

@@ -26,17 +26,18 @@ query = URI.escape(sparql(untaint(q))) "http://vocab.getty.edu/sparql.json?query=#{URI.escape(sparql(q))}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql" end def sparql(q) - sparql = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> - SELECT * WHERE { ?s skos:prefLabel ?name . - ?s skos:inScheme <http://vocab.getty.edu/#{@sub_authority}/> . - ?s rdf:type <http://vocab.getty.edu/ontology#Concept> . - FILTER regex(?name, \"#{untaint(q)}\", \"i\") . - FILTER langMatches( lang(?name), \"EN\" ) . - } LIMIT 10" + search = untaint(q) + # The full text index matches on fields besides the term, so we filter to ensure the match is in the term. + sparql = "SELECT ?s ?name { + ?s a skos:Concept; luc:term \"#{search}\"; + skos:inScheme <http://vocab.getty.edu/#{@sub_authority}/> ; + gvp:prefLabelGVP [skosxl:literalForm ?name]. + FILTER regex(?name, \"#{search}\", \"i\") . + } LIMIT 10" end def untaint(q) q.gsub(/[^\w\s-]/, '') end @@ -48,11 +49,10 @@ def find_url id "http://vocab.getty.edu/#{@sub_authority}/#{id}.json" end def request_options - # Don't pass a request header. See http://answers.semanticweb.com/questions/31906/getty-sparql-gives-a-404-if-you-pass-accept-applicationjson - { } + { accept: 'application/sparql-results+json'} end private # Reformats the data received from the LOC service