Class: Qiita::Elasticsearch::Nodes::FilterNode

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita/elasticsearch/nodes/filter_node.rb

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ FilterNode



9
10
11
# File 'lib/qiita/elasticsearch/nodes/filter_node.rb', line 9

def initialize(tokens)
  @tokens = tokens
end

Instance Method Details

#to_hashObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/qiita/elasticsearch/nodes/filter_node.rb', line 13

def to_hash
  if must_not_tokens.empty? && must_tokens.length == 1
    TermNode.new(must_tokens.first).to_hash
  else
    {
      "bool" => {
        "_cache" => true,
        "must" => must_queries,
        "must_not" => must_not_queries,
      }.reject do |key, value|
        value.is_a?(Array) && value.empty?
      end,
    }
  end
end