Class: Polecat::Query

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

Overview

The Query manages a number of terms or queries which are set into a relation. A relation is needed to say, which documents shall be returned. In a @and@ relation only the documents, which are returned of the query parts get returned. For @or@ all documents found in a part get returned.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation = :and) ⇒ Query

creates a new query object

Create a new query object. As a default, the relation is set to @:and@ (@see Query#relation)



19
20
21
22
23
24
25
26
27
# File 'lib/polecat/query.rb', line 19

def initialize relation = :and
  if relation == :and || relation == :or
    @relation = relation
  else
    raise ArgumentError, 'no valid relation'
  end

  @terms = []
end

Instance Attribute Details

#relationSymbol

returns the relation of the terms

Returns:

  • (Symbol)

    :and, :or



10
11
12
# File 'lib/polecat/query.rb', line 10

def relation
  @relation
end

#termsObject (readonly)

returns the list of all terms



13
14
15
# File 'lib/polecat/query.rb', line 13

def terms
  @terms
end

Instance Method Details

#add(term) ⇒ Object

add a new term or query



30
31
32
33
# File 'lib/polecat/query.rb', line 30

def add term
  @terms << term
  self
end