Class: Qiita::Elasticsearch::Nodes::OrSeparatableNode

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

Instance Method Summary collapse

Constructor Details

#initialize(tokens, matchable_fields: nil) ⇒ OrSeparatableNode



10
11
12
13
# File 'lib/qiita/elasticsearch/nodes/or_separatable_node.rb', line 10

def initialize(tokens, matchable_fields: nil)
  @matchable_fields = matchable_fields
  @tokens = tokens
end

Instance Method Details

#to_hashObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/qiita/elasticsearch/nodes/or_separatable_node.rb', line 15

def to_hash
  case tokens_grouped_by_or_token.size
  when 0
    Nodes::NullNode.new.to_hash
  when 1
    Nodes::BoolQueryNode.new(
      tokens_grouped_by_or_token.first,
      matchable_fields: @matchable_fields,
    ).to_hash
  else
    {
      "bool" => {
        "should" => tokens_grouped_by_or_token.map do |tokens|
          Nodes::BoolQueryNode.new(
            tokens,
            matchable_fields: @matchable_fields,
          ).to_hash
        end,
      },
    }
  end
end