Module: ActiveFedora::SolrQueryBuilder
- Defined in:
- lib/active_fedora/solr_query_builder.rb
Class Method Summary collapse
-
.construct_query_for_ids(id_array) ⇒ Object
Construct a solr query for a list of ids This is used to get a solr response based on the list of ids in an object’s RELS-EXT relationhsips If the id_array is empty, defaults to a query of “id:NEVER_USE_THIS_ID”, which will return an empty solr response.
-
.construct_query_for_rel(field_pairs, join_with = 'AND') ⇒ Object
Create a query with a clause for each key, value.
-
.raw_query(key, value) ⇒ Object
Create a raw query clause suitable for sending to solr as an fq element.
- .solr_name(*args) ⇒ Object
Class Method Details
.construct_query_for_ids(id_array) ⇒ Object
Construct a solr query for a list of ids This is used to get a solr response based on the list of ids in an object’s RELS-EXT relationhsips If the id_array is empty, defaults to a query of “id:NEVER_USE_THIS_ID”, which will return an empty solr response
7 8 9 10 |
# File 'lib/active_fedora/solr_query_builder.rb', line 7 def self.construct_query_for_ids(id_array) q = id_array.reject { |x| x.blank? }.map { |id| raw_query(SOLR_DOCUMENT_ID, id) } q.empty? ? "id:NEVER_USE_THIS_ID" : q.join(" OR ".freeze) end |
.construct_query_for_rel(field_pairs, join_with = 'AND') ⇒ Object
Create a query with a clause for each key, value
31 32 33 34 35 36 |
# File 'lib/active_fedora/solr_query_builder.rb', line 31 def self.construct_query_for_rel(field_pairs, join_with = 'AND') field_pairs = field_pairs.to_a if field_pairs.kind_of? Hash clauses = pairs_to_clauses(field_pairs.reject { |_, target_uri| target_uri.blank? }) clauses.empty? ? "id:NEVER_USE_THIS_ID" : clauses.join(" #{join_with} ".freeze) end |
.raw_query(key, value) ⇒ Object
Create a raw query clause suitable for sending to solr as an fq element
15 16 17 |
# File 'lib/active_fedora/solr_query_builder.rb', line 15 def self.raw_query(key, value) "_query_:\"{!raw f=#{key}}#{value.gsub('"', '\"')}\"" end |
.solr_name(*args) ⇒ Object
19 20 21 |
# File 'lib/active_fedora/solr_query_builder.rb', line 19 def self.solr_name(*args) Solrizer.default_field_mapper.solr_name(*args) end |