Class: XTF::Search::Element::Query
- 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
Instance Attribute Summary collapse
-
#content ⇒ Object
one Term or Clause, spellcheck, and any number of facet tags all in an array.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
-
#term=(value) ⇒ Object
Accepts a
Term
or aString
which is converted to aTerm
and adds it to thecontent
. - #to_xml ⇒ Object
- #to_xml_node ⇒ Object
Methods inherited from Base
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
#content ⇒ Object
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_xml ⇒ Object
38 39 40 |
# File 'lib/xtf/search/element/query.rb', line 38 def to_xml to_xml_node.to_s end |
#to_xml_node ⇒ Object
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 |