module ROM::Solr::Query

Constants

AFTER_DATE
AND
ANY_VALUE
BEFORE_DATE
BETWEEN_DATES
DISJUNCTION

Templates

ESCAPE
EXACT_DATE
INTEGER
JOIN
NEGATION
NOOP

Value transformers

OR
REGEXP
STANDARD
TERM

Public Instance Methods

after(mapping) click to toggle source

Builds query clause(s) to filter where date field value is later than a date/time value.

@param mapping [Hash] field=>value mapping

Values (coerced to strings) must be parseable by `DateTime.parse`.

@return [Array<String>] queries

# File lib/rom/solr/query.rb, line 96
def after(mapping)
  render(STANDARD, mapping, AFTER_DATE)
end
before(mapping) click to toggle source

Builds query clause(s) to filter where date field value is earlier than a date/time value.

@param mapping [Hash] field=>value mapping

Values (coerced to strings) must be parseable by `DateTime.parse`.

@return [Array<String>] queries

# File lib/rom/solr/query.rb, line 86
def before(mapping)
  render(STANDARD, mapping, BEFORE_DATE)
end
between_dates(mapping) click to toggle source
# File lib/rom/solr/query.rb, line 100
def between_dates(mapping)
  render(STANDARD, mapping, BETWEEN_DATES)
end
exact_date(mapping) click to toggle source
# File lib/rom/solr/query.rb, line 104
def exact_date(mapping)
  render(STANDARD, mapping, EXACT_DATE)
end
exist(*fields) click to toggle source

Builds query clause(s) to filter where field is present (i.e., has one or more values)

@param fields [Array<String>] on or more fields @return [Array<String>] queries

# File lib/rom/solr/query.rb, line 51
def exist(*fields)
  mapping = fields.map { |field| {field: field, value: ANY_VALUE} }

  render(STANDARD, mapping)
end
join(from:, to:, field:, value:) click to toggle source

Builds a Solr join clause

@see wiki.apache.org/solr/Join @param from [String] @param to [String] @param field [String] @param value [String] @return [Array<String>] queries

# File lib/rom/solr/query.rb, line 76
def join(from:, to:, field:, value:)
  [ JOIN % { from: from, to: to, field: field, value: value } ]
end
not_exist(*fields) click to toggle source

Builds query clause(s) to filter where field is NOT present (i.e., no values)

@param fields [Array<Symbol, String>] one or more fields @return [Array<String>] queries

# File lib/rom/solr/query.rb, line 62
def not_exist(*fields)
  mapping = fields.map { |field| {field: "-#{field}", value: ANY_VALUE} }

  render(STANDARD, mapping)
end
regexp(mapping) click to toggle source

Builds regular expression query clause(s).

@param mapping [Hash] field=>value mapping @return [Array<String>] queries

# File lib/rom/solr/query.rb, line 120
def regexp(mapping)
  render(REGEXP, mapping, ESCAPE_SLASHE)
end
term(mapping) click to toggle source

Builds term query clause(s) to filter where field contains value.

@param mapping [Hash] field=>value mapping @return [Array<String>] queries

# File lib/rom/solr/query.rb, line 112
def term(mapping)
  render(TERM, mapping)
end
where(mapping) click to toggle source

Build standard query clause(s) – i.e., field:value – and disjunction clauses (i.e., when value is an array).

@param mapping [Hash] field=>value mapping @return [Array<String>] queries

# File lib/rom/solr/query.rb, line 34
def where(mapping)
  render(STANDARD, mapping, ->(v) { Array.wrap(v).join(OR) })
end
where_not(mapping) click to toggle source

Builds negation clause(s) – i.e., -field:value

@param mapping [Hash] field=>value mapping @return [Array<String>] queries

# File lib/rom/solr/query.rb, line 42
def where_not(mapping)
  render(NEGATION, mapping)
end

Private Instance Methods

render(template, mapping, transformer = NOOP) click to toggle source
# File lib/rom/solr/query.rb, line 126
def render(template, mapping, transformer = NOOP)
  mapping.transform_values(&transformer).map do |field, value|
    template % {field: field, value: value}
  end
end