Module: ActiveFedora::SolrQueryBuilder
- Defined in:
- lib/active_fedora/solr_query_builder.rb
Class Method Summary collapse
-
.construct_query(field_pairs, join_with = default_join_with, type = 'field'.freeze) ⇒ String
Construct a solr query from a list of pairs (e.g. [field name, values]).
-
.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 = default_join_with) ⇒ Object
Create a raw query with a clause for each key, value.
- .default_join_with ⇒ Object
Class Method Details
.construct_query(field_pairs, join_with = default_join_with, type = 'field'.freeze) ⇒ String
Construct a solr query from a list of pairs (e.g. [field name, values])
35 36 37 38 39 40 |
# File 'lib/active_fedora/solr_query_builder.rb', line 35 def construct_query(field_pairs, join_with = default_join_with, type = 'field'.freeze) clauses = pairs_to_clauses(field_pairs, type) return "" if clauses.count.zero? return clauses.first if clauses.count == 1 "(#{clauses.join(join_with)})" end |
.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
8 9 10 11 12 |
# File 'lib/active_fedora/solr_query_builder.rb', line 8 def construct_query_for_ids(id_array) ids = id_array.reject(&:blank?) return "id:NEVER_USE_THIS_ID" if ids.empty? "{!terms f=#{ActiveFedora.id_field}}#{ids.join(',')}" end |
.construct_query_for_rel(field_pairs, join_with = default_join_with) ⇒ Object
Create a raw query with a clause for each key, value
22 23 24 25 |
# File 'lib/active_fedora/solr_query_builder.rb', line 22 def construct_query_for_rel(field_pairs, join_with = default_join_with) field_pairs = field_pairs.to_a if field_pairs.is_a? Hash construct_query(property_values_to_solr(field_pairs), join_with, 'raw'.freeze) end |
.default_join_with ⇒ Object
42 43 44 |
# File 'lib/active_fedora/solr_query_builder.rb', line 42 def default_join_with ' AND ' end |