Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create and search requests do work always #234

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions app/services/triannon/ldp_to_oa_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand All @@ -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]

Expand All @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
18 changes: 15 additions & 3 deletions app/services/triannon/solr_searcher.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -107,10 +119,10 @@ def self.solr_params(controller_params)
# @return [Array<String>] 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
Expand Down
13 changes: 12 additions & 1 deletion config/solr/triannon-core/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,19 @@
<filter class="solr.ICUFoldingFilterFactory"/>
<filter class="solr.TrimFilterFactory" />
</analyzer>
<!--
cf. http://wiki.apache.org/solr/MultitermQueryAnalysis
Without this the charFilters are not executed at query time when doing a wildcard search? Add debugQuery=on too see this.
-->
<analyzer type="multiterm">
<charFilter class="solr.PatternReplaceCharFilterFactory" pattern="^\s*https?\:\/\/" replacement=""/>
<charFilter class="solr.PatternReplaceCharFilterFactory" pattern="\/\s*$" replacement=""/>
<tokenizer class="solr.KeywordTokenizerFactory" />
<filter class="solr.ICUFoldingFilterFactory"/>
<filter class="solr.TrimFilterFactory" />
</analyzer>
</fieldType>

</types>

</schema>
</schema>