Class: Ferret::Search::TermQuery

Inherits:
Query
  • Object
show all
Defined in:
lib/ferret/search/term_query.rb

Overview

A Query that matches documents containing a @term.

This may be combined with other terms with a BooleanQuery.

Defined Under Namespace

Classes: TermWeight

Instance Attribute Summary collapse

Attributes inherited from Query

#boost

Instance Method Summary collapse

Methods inherited from Query

#combine, #merge_boolean_queries, #rewrite, #similarity, #weight

Constructor Details

#initialize(t) ⇒ TermQuery

Constructs a query for the @query.term t.



93
94
95
96
# File 'lib/ferret/search/term_query.rb', line 93

def initialize(t) 
  super()
  @term = t
end

Instance Attribute Details

#termObject (readonly)

Returns the value of attribute term.



6
7
8
# File 'lib/ferret/search/term_query.rb', line 6

def term
  @term
end

Instance Method Details

#create_weight(searcher) ⇒ Object



98
99
100
# File 'lib/ferret/search/term_query.rb', line 98

def create_weight(searcher)
  return TermWeight.new(self, searcher)
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns true iff o is equal to this.

Returns:

  • (Boolean)


116
117
118
119
# File 'lib/ferret/search/term_query.rb', line 116

def eql?(other) 
  return false if not other.instance_of?(TermQuery)
  return (@boost == other.boost and @term == other.term)
end

#extract_terms(terms) ⇒ Object



102
103
104
# File 'lib/ferret/search/term_query.rb', line 102

def extract_terms(terms) 
  terms << @term
end

#hashObject

Returns a hash code value for this object.



123
124
125
# File 'lib/ferret/search/term_query.rb', line 123

def hash() 
  return @boost.hash ^ @term.hash
end

#to_s(field = nil) ⇒ Object

Prints a user-readable version of this query.



107
108
109
110
111
112
113
# File 'lib/ferret/search/term_query.rb', line 107

def to_s(field = nil) 
  buffer = ""
  buffer << "#{@term.field}:" if field != @term.field
  buffer << "#{@term.text}"
  buffer << "^#{@boost}" if @boost != 1.0
  return buffer
end