Module: Rubydora::ResourceIndex
- Included in:
- Repository
- Defined in:
- lib/rubydora/resource_index.rb
Overview
Fedora resource index helpers
Instance Method Summary collapse
-
#find_by_sparql(query, options = { :binding => 'pid' }) ⇒ Array<Rubydora::DigitalObject>
Find new objects using a sparql query.
-
#find_by_sparql_relationship(subject, predicate) ⇒ Array<Rubydora::DigitalObject>
Find new objects by their relationship to a subject.
-
#risearch(query, options = {}) ⇒ Object
Run a raw query against the Fedora risearch resource index.
-
#sparql(query) ⇒ FasterCSV::Table
Run a raw SPARQL query and return a FasterCSV object.
Instance Method Details
#find_by_sparql(query, options = { :binding => 'pid' }) ⇒ Array<Rubydora::DigitalObject>
Find new objects using a sparql query
11 12 13 14 15 16 17 18 |
# File 'lib/rubydora/resource_index.rb', line 11 def find_by_sparql query, = { :binding => 'pid' } return to_enum(:find_by_sparql, query, ).to_a unless block_given? self.sparql(query).each do |x| obj = self.find(x[[:binding]]) rescue nil yield obj if obj end end |
#find_by_sparql_relationship(subject, predicate) ⇒ Array<Rubydora::DigitalObject>
Find new objects by their relationship to a subject
24 25 26 27 28 29 30 |
# File 'lib/rubydora/resource_index.rb', line 24 def find_by_sparql_relationship subject, predicate find_by_sparql <<-RELSEXT SELECT ?pid FROM <#ri> WHERE { <#{subject}> <#{predicate}> ?pid } RELSEXT end |
#risearch(query, options = {}) ⇒ Object
Run a raw query against the Fedora risearch resource index
46 47 48 49 50 |
# File 'lib/rubydora/resource_index.rb', line 46 def risearch query, = {} request_params = { :dt => 'on', :format => 'CSV', :lang => 'sparql', :limit => nil, :query => query, :type => 'tuples' }.merge() self.client['risearch'].post request_params end |
#sparql(query) ⇒ FasterCSV::Table
Run a raw SPARQL query and return a FasterCSV object
35 36 37 38 39 40 41 |
# File 'lib/rubydora/resource_index.rb', line 35 def sparql query if CSV.const_defined? :Reader FasterCSV.parse(self.risearch(query), :headers => true) else CSV.parse(self.risearch(query), :headers => true) end end |