Class: XTF::Search::Element::Query

Inherits:
Base
  • Object
show all
Defined in:
lib/xtf/search/element/query.rb

Constant Summary collapse

STYLE_DEFAULT =
"style/crossQuery/resultFormatter/default/resultFormatter.xsl"
INDEX_PATH_DEFAULT =
"index"

Constants inherited from Base

Base::BASE_ATTRIBUTE_KEYS

Instance Attribute Summary collapse

Attributes inherited from Base

#tag_name

Instance Method Summary collapse

Methods inherited from Base

attribute_keys, #attributes

Constructor Details

#initialize(*args) ⇒ Query

Returns a new instance of Query.



11
12
13
14
15
16
17
18
19
# File 'lib/xtf/search/element/query.rb', line 11

def initialize(*args)
  @tag_name = 'query'
  params = args[0] || {}
  self.content = params.delete(:content) || []
  super(params)

  @style ||= STYLE_DEFAULT
  @index_path ||= INDEX_PATH_DEFAULT
end

Instance Attribute Details

#contentObject

one Term or Clause, spellcheck, and any number of facet tags all in an array



9
10
11
# File 'lib/xtf/search/element/query.rb', line 9

def content
  @content
end

Instance Method Details

#term=(value) ⇒ Object

Accepts a Term or a String which is converted to a Term and adds it to the content.



22
23
24
# File 'lib/xtf/search/element/query.rb', line 22

def term=(value)
  self.content << (value.is_a?(XTF::Search::Element::Term) ? value : XTF::Search::Element::Term.new(value))
end

#to_xmlObject



38
39
40
# File 'lib/xtf/search/element/query.rb', line 38

def to_xml
  to_xml_node.to_s
end

#to_xml_nodeObject



31
32
33
34
35
36
37
# File 'lib/xtf/search/element/query.rb', line 31

def to_xml_node
  xml = XTF::XML::Element.new(self.tag_name)
  self.attributes.each_pair { |key, value| xml.attributes[key.to_s.camelize(:lower)] = value if value}
  # TODO validate only one term or clause present?
  self.content.each {|node| xml.add_element(node.to_xml_node)}
  xml
end