module ActiveFedora::SolrQueryBuilder
def condition_to_clauses(field, values)
-
(Array
-)
Parameters:
-
values
(String, Array
) -- -
field
(String
) --
def condition_to_clauses(field, values) values = Array(values) values << nil if values.empty? values.map do |value| if value.present? field_query(field, value) else # Check that the field is not present. In SQL: "WHERE field IS NULL" "-#{field}:[* TO *]" end end end
def construct_query(field_pairs, join_with = ' AND ')
-
(String)
- a solr query
Parameters:
-
join_with
(String
) -- ('AND') the value we're joining the clauses with -
field_pairs
(Array
) -- a list of pairs of property name and values
def construct_query(field_pairs, join_with = ' AND ') pairs_to_clauses(field_pairs).join(join_with) end
def construct_query_for_ids(id_array)
-
id_array
(Array
) -- the ids that you want included in the query
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
def construct_query_for_rel(field_pairs, join_with = ' AND ')
-
join_with
(String
) -- ('AND') the value we're joining the clauses with -
field_pairs
(Hash, Array
) -- key is the predicate, value is the target_uri>
def construct_query_for_rel(field_pairs, join_with = ' AND ') field_pairs = field_pairs.to_a if field_pairs.is_a? Hash construct_query(property_values_to_solr(field_pairs), join_with) end
def field_query(key, value)
-
value
(String
) -- -
key
(String
) --
def field_query(key, value) "_query_:\"{!field f=#{key}}#{value.gsub('"', '\"')}\"" end
def pairs_to_clauses(pairs)
-
(Array)
- a list of solr clauses
Parameters:
-
pairs
(Array
) -- a list of (key, value) pairs. The value itself may
def pairs_to_clauses(pairs) pairs.flat_map do |field, value| condition_to_clauses(field, value) end end
def property_values_to_solr(pairs)
-
(Hash)
- map of solr fields to values
Parameters:
-
pairs
(Array
) -- a list of pairs of property name and values
def property_values_to_solr(pairs) pairs.map do |(property, value)| [solr_field(property), value] end end
def raw_query(key, value)
-
value
(String
) -- -
key
(String
) --
def raw_query(key, value) Deprecation.warn(ActiveFedora::SolrQueryBuilder, 'ActiveFedora::SolrQueryBuilder.raw_query is deprecated and will be removed in ActiveFedora 10.0. Use .construct_query instead.') "_query_:\"{!raw f=#{key}}#{value.gsub('"', '\"')}\"" end
def solr_field(field)
-
(String)
- the corresponding solr field for the string
Parameters:
-
field
(String, ActiveFedora::Relation
) --
def solr_field(field) case field when ActiveFedora::Reflection::AssociationReflection field.solr_key else ActiveFedora.index_field_mapper.solr_name(field, :symbol) end end
def solr_name(*args)
def solr_name(*args) Deprecation.warn(ActiveFedora::SolrQueryBuilder, 'ActiveFedora::SolrQueryBuilder.solr_name is deprecated and will be removed in ActiveFedora 10.0. Use ActiveFedora.index_field_mapper.solr_name instead.') ActiveFedora.index_field_mapper.solr_name(*args) end