Class: Sunspot::Query::AbstractFulltext

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

Overview

Solr query abstraction

Direct Known Subclasses

Dismax, Join

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fulltext_fieldsObject (readonly)

Returns the value of attribute fulltext_fields.



8
9
10
# File 'lib/sunspot/query/abstract_fulltext.rb', line 8

def fulltext_fields
  @fulltext_fields
end

Instance Method Details

#add_additive_boost_function(function_query) ⇒ Object

Add a boost function



21
22
23
24
25
# File 'lib/sunspot/query/abstract_fulltext.rb', line 21

def add_additive_boost_function(function_query)
  unless @additive_boost_functions.include?(function_query)
    @additive_boost_functions << function_query
  end
end

#add_boost_query(factor) ⇒ Object

Assign a new boost query and return it.



13
14
15
16
# File 'lib/sunspot/query/abstract_fulltext.rb', line 13

def add_boost_query(factor)
  @boost_queries << boost_query = BoostQuery.new(factor)
  boost_query
end

#add_fulltext_field(field, boost = nil) ⇒ Object

Add a fulltext field to be searched, with optional boost.



39
40
41
# File 'lib/sunspot/query/abstract_fulltext.rb', line 39

def add_fulltext_field(field, boost = nil)
  @fulltext_fields[field.indexed_name] = TextFieldBoost.new(field, boost)
end

#add_highlight(fields = [], options = {}) ⇒ Object

Set highlighting options for the query. If fields is empty, the Highlighting object won’t pass field names at all, which means the dismax’s :qf parameter will be used by Solr.



56
57
58
# File 'lib/sunspot/query/abstract_fulltext.rb', line 56

def add_highlight(fields=[], options={})
  @highlights << Highlighting.new(fields, options)
end

#add_multiplicative_boost_function(function_query) ⇒ Object

Add a multiplicative boost function



30
31
32
33
34
# File 'lib/sunspot/query/abstract_fulltext.rb', line 30

def add_multiplicative_boost_function(function_query)
  unless @multiplicative_boost_functions.include?(function_query)
    @multiplicative_boost_functions << function_query
  end
end

#add_phrase_field(field, boost = nil) ⇒ Object

Add a phrase field for extra boost.



46
47
48
49
# File 'lib/sunspot/query/abstract_fulltext.rb', line 46

def add_phrase_field(field, boost = nil)
  @phrase_fields ||= []
  @phrase_fields << TextFieldBoost.new(field, boost)
end

#has_fulltext_field?(field) ⇒ Boolean

Determine if a given field is being searched. Used by DSL to avoid overwriting boost parameters when injecting defaults.

Returns:

  • (Boolean)


64
65
66
# File 'lib/sunspot/query/abstract_fulltext.rb', line 64

def has_fulltext_field?(field)
  @fulltext_fields.has_key?(field.indexed_name)
end