diff --git a/app/services/triannon/ldp_to_oa_mapper.rb b/app/services/triannon/ldp_to_oa_mapper.rb index 106fd369..c6c097da 100644 --- a/app/services/triannon/ldp_to_oa_mapper.rb +++ b/app/services/triannon/ldp_to_oa_mapper.rb @@ -27,7 +27,8 @@ def initialize(ldp_anno, root_container) # load statements from base anno container into @oa_graph def extract_base root_subject_solns = @ldp_anno_graph.query OA::Graph.anno_query - if root_subject_solns.count == 1 + #for some reason the query returns nil instead of an empty array? + if root_subject_solns && root_subject_solns.count == 1 stored_url = Triannon.config[:ldp]['url'].strip stored_url.chop! if stored_url.end_with?('/') uber_container = Triannon.config[:ldp]['uber_container'].strip @@ -83,7 +84,8 @@ def extract_targets # @return [Boolean] true if it adds statements to @oa_graph, false otherwise def map_external_ref uri_obj, predicate, subject_obj = @root_uri solns = @ldp_anno_graph.query [uri_obj, RDF::Triannon.externalReference, nil] - if solns.count > 0 + #for some reason the query returns nil instead of an empty array? + if solns && solns.count > 0 external_uri = solns.first.object @oa_graph << [subject_obj, predicate, external_uri] @@ -109,7 +111,8 @@ def map_external_ref uri_obj, predicate, subject_obj = @root_uri # @return [Boolean] true if it adds statements to @oa_graph, false otherwise def map_content_as_text uri_obj, predicate, subject_obj = @root_uri solns = @ldp_anno_graph.query [uri_obj, RDF.type, RDF::Vocab::CNT.ContentAsText] - if solns.count > 0 + #for some reason the query returns nil instead of an empty array? + if solns && solns.count > 0 blank_node = RDF::Node.new @oa_graph << [subject_obj, predicate, blank_node] @@ -135,7 +138,8 @@ def map_content_as_text uri_obj, predicate, subject_obj = @root_uri # @return [Boolean] true if it adds statements to @oa_graph, false otherwise def map_specific_resource uri_obj, predicate solns = @ldp_anno_graph.query [uri_obj, RDF.type, RDF::Vocab::OA.SpecificResource] - if solns.count > 0 + #for some reason the query returns nil instead of an empty array? + if solns && solns.count > 0 blank_node = RDF::Node.new @oa_graph << [@root_uri, predicate, blank_node] @@ -188,7 +192,8 @@ def map_specific_resource uri_obj, predicate # @return [Boolean] true if it adds statements to @oa_graph, false otherwise def map_choice uri_obj, predicate solns = @ldp_anno_graph.query [uri_obj, RDF.type, RDF::Vocab::OA.Choice] - if solns.count > 0 + #for some reason the query returns nil instead of an empty array? + if solns && solns.count > 0 blank_node = RDF::Node.new @oa_graph << [@root_uri, predicate, blank_node] diff --git a/app/services/triannon/solr_searcher.rb b/app/services/triannon/solr_searcher.rb index 520f7f45..a3558619 100644 --- a/app/services/triannon/solr_searcher.rb +++ b/app/services/triannon/solr_searcher.rb @@ -1,6 +1,14 @@ module Triannon class SolrSearcher + def self.to_natural(n) + i = nil + begin + i = Integer(n) + end + !(i.nil?) && i >= 0 ? i : 0 + end + # convert RSolr::Response object into an array of OA::Graph objects, # where each graph object contains a single annotation returned in the response docs # @param [Hash] rsolr_response an RSolr response to a query. It's actually an @@ -68,6 +76,10 @@ def self.solr_params(controller_params) end when 'anno_root' fq_terms_array << "root:#{RSolr.solr_escape(v)}" + when 'start' + solr_params_hash[:start] = to_natural( v ) + when 'limit' + solr_params_hash[:rows] = to_natural( v ) # TODO: add'l params to implement: # targetType - fq @@ -107,10 +119,10 @@ def self.solr_params(controller_params) # @return [Array] an array of query terms to be added to the Solr q argument def self.q_terms_for_url(fieldname, url) q_terms = [] - q_terms << "#{fieldname}:#{RSolr.solr_escape(url)}" if !url.include? '#' - # Note: do NOT Solr escape the # (unnec) or the * (want Solr to view it as wildcard) - q_terms << "#{fieldname}:#{RSolr.solr_escape(url)}#*" + q_terms << "#{fieldname}:#{RSolr.solr_escape(url)}*" + else + q_terms << "#{fieldname}:#{RSolr.solr_escape(url)}" end q_terms end diff --git a/config/solr/triannon-core/conf/schema.xml b/config/solr/triannon-core/conf/schema.xml index d94ee4e4..862d6954 100644 --- a/config/solr/triannon-core/conf/schema.xml +++ b/config/solr/triannon-core/conf/schema.xml @@ -97,8 +97,19 @@ + + + + + + + + - \ No newline at end of file +