Module: Sunspot::DSL::Functional
- Included in:
- Fulltext
- Defined in:
- lib/sunspot/dsl/functional.rb
Overview
Mixin DSL to accept functions.
Instance Method Summary collapse
-
#create_function_query(expression) ⇒ Object
Creates an AbstractFunctionQuery from an expression, also called by Sunspot::DSL::Function.
-
#function(&block) ⇒ Object
Specify a function query with a block that returns an expression.
Instance Method Details
#create_function_query(expression) ⇒ Object
Creates an AbstractFunctionQuery from an expression, also called by Sunspot::DSL::Function
29 30 31 32 33 34 35 36 37 |
# File 'lib/sunspot/dsl/functional.rb', line 29 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 |
#function(&block) ⇒ Object
Specify a function query with a block that returns an expression.
Examples
function { 10 }
function { :average_rating }
function { sum(:average_rating, 10) }
17 18 19 20 21 22 23 |
# File 'lib/sunspot/dsl/functional.rb', line 17 def function(&block) expression = Sunspot::Util.instance_eval_or_call( Function.new(self), &block ) create_function_query(expression) end |