Module: Sunspot::DSL::Functional
- Included in:
- Fulltext
- Defined in:
- sunspot/lib/sunspot/dsl/functional.rb
Overview
Mixin DSL to accept functions.
Instance Method Summary (collapse)
-
- (Object) create_function_query(expression)
Creates an AbstractFunctionQuery from an expression, also called by Sunspot::DSL::Function.
-
- (Object) function(&block)
Specify a function query with a block that returns an expression.
Instance Method Details
- (Object) create_function_query(expression)
Creates an AbstractFunctionQuery from an expression, also called by Sunspot::DSL::Function
32 33 34 35 36 37 38 39 40 |
# File 'sunspot/lib/sunspot/dsl/functional.rb', line 32 def create_function_query(expression) #:nodoc: if expression.is_a?(Sunspot::Query::FunctionQuery) expression elsif expression.is_a?(Symbol) Sunspot::Query::FieldFunctionQuery.new(@setup.field(expression)) else Sunspot::Query::ConstantFunctionQuery.new(expression) end end |
- (Object) function(&block)
Specify a function query with a block that returns an expression.
Examples
function { 10 } function { :average_rating } function { sum(:average_rating, 10) }
See wiki.apache.org/solr/FunctionQuery for a list of all applicable functions
20 21 22 23 24 25 26 |
# File 'sunspot/lib/sunspot/dsl/functional.rb', line 20 def function(&block) expression = Sunspot::Util.instance_eval_or_call( Function.new(self), &block ) create_function_query(expression) end |