Class: Sunspot::Query::FieldQuery

Inherits:
Scope
  • Object
show all
Defined in:
lib/sunspot/query/field_query.rb

Overview

This class acts as a base class for query components that encapsulate operations on fields. It is subclassed by the Query::Query class and the Query::DynamicQuery class.

Direct Known Subclasses

DynamicQuery, Query

Instance Method Summary collapse

Methods inherited from Scope

#add_conjunction, #add_disjunction, #add_negated_restriction, #add_negated_shorthand_restriction, #add_restriction, #add_shorthand_restriction, #dynamic_query, #exclude_instance

Instance Method Details

#add_field_facet(field_name, options = nil) ⇒ Object

Add a field facet. See Sunspot::Facet for more information.

Parameters

field_name<Symbol>

Name of the field on which to get a facet

Returns

FieldFacet

The field facet object



20
21
22
23
24
25
26
27
28
29
# File 'lib/sunspot/query/field_query.rb', line 20

def add_field_facet(field_name, options = nil)
  options ||= {}
  facet =
    if only = options.delete(:only)
      query_facets[field_name.to_sym] = QueryFieldFacet.new(@setup.field(field_name), only) 
    else
      FieldFacet.build(build_field(field_name), options)
    end
  add_component(facet)
end

#add_query_facet(name) ⇒ Object

Add a query facet.

Parameters

name<Symbol>

The name associated with the query facet. This is not passed to Solr, but allows the user to retrieve the facet result by passing the name to the Search#facet method.

Returns

QueryFacet

The query facet object



45
46
47
48
# File 'lib/sunspot/query/field_query.rb', line 45

def add_query_facet(name)
  add_component(facet = QueryFacet.new(name, setup))
  query_facets[name.to_sym] = facet
end

#order_by(field_name, direction = nil) ⇒ Object

Set result ordering.

Parameters

field_name<Symbol>

Name of the field on which to order

direction<Symbol>

:asc or :desc (default :asc)



58
59
60
# File 'lib/sunspot/query/field_query.rb', line 58

def order_by(field_name, direction = nil)
  add_sort(Sort.new(build_field(field_name), direction))
end