Class: Ferret::Search::BooleanClause

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

Overview

A clause in a BooleanQuery.

Defined Under Namespace

Classes: Occur

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, occur = Occur::SHOULD) ⇒ BooleanClause

Constructs a BooleanClause. Default value for occur is Occur::SHOULD



55
56
57
58
59
# File 'lib/ferret/search/boolean_clause.rb', line 55

def initialize(query, occur = Occur::SHOULD) 
  @query = query
  @occur = occur
  set_fields(occur)
end

Instance Attribute Details

#occurObject

See BooleanQuery::Occur for values for this attribute



48
49
50
# File 'lib/ferret/search/boolean_clause.rb', line 48

def occur
  @occur
end

#prohibited=(value) ⇒ Object (writeonly)

If true, documents documents which do match this sub-query will not match the boolean query.



42
43
44
# File 'lib/ferret/search/boolean_clause.rb', line 42

def prohibited=(value)
  @prohibited = value
end

#queryObject

The query whose matching documents are combined by the boolean query.



31
32
33
# File 'lib/ferret/search/boolean_clause.rb', line 31

def query
  @query
end

#required=(value) ⇒ Object (writeonly)

If true, documents documents which _do not_ match this sub-query will not match the boolean query.



35
36
37
# File 'lib/ferret/search/boolean_clause.rb', line 35

def required=(value)
  @required = value
end

Instance Method Details

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

Returns true iff other is equal to this.

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
# File 'lib/ferret/search/boolean_clause.rb', line 63

def eql?(other) 
  if not other.instance_of?(BooleanClause)
    return false
  end
  return (@query == other.query and
          @required == other.required? and
          @prohibited == other.prohibited?)
end

#hashObject

Returns a hash code value for this object.



74
75
76
# File 'lib/ferret/search/boolean_clause.rb', line 74

def hash() 
  return @query.hash() ^ (@required ? 1 : 0) ^ (@prohibited ? 2 : 0)
end

#prohibited?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ferret/search/boolean_clause.rb', line 43

def prohibited?
  @prohibited
end

#required?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ferret/search/boolean_clause.rb', line 36

def required?
  @required
end

#to_sObject

represent a boolean clause as a string



79
80
81
# File 'lib/ferret/search/boolean_clause.rb', line 79

def to_s() 
  return @occur.to_s() + @query.to_s()
end