Class: PrettySearch::SimpleQuery

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

Overview

Simple query that matches returns matches when all fields matches fully

Constant Summary collapse

SIMPLE_PATTERN =
/\A([\w ]+)=(.+)\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Query

parse, parse_simple

Constructor Details

#initialize(attr) ⇒ SimpleQuery

Returns a new instance of SimpleQuery.



52
53
54
# File 'lib/pretty_search/query.rb', line 52

def initialize(attr)
  @attr = attr
end

Instance Attribute Details

#attrObject (readonly)

Returns the value of attribute attr.



50
51
52
# File 'lib/pretty_search/query.rb', line 50

def attr
  @attr
end

Instance Method Details

#==(o) ⇒ Object

Used in specs



67
68
69
# File 'lib/pretty_search/query.rb', line 67

def ==(o)
  attr == o.attr
end

#[](key) ⇒ Object



62
63
64
# File 'lib/pretty_search/query.rb', line 62

def [](key)
  attr[key]
end

#match(doc) ⇒ Object



56
57
58
59
60
# File 'lib/pretty_search/query.rb', line 56

def match(doc)
  attr.all? do |key, value|
    doc[key] == value # floats are compared as strings
  end
end