Class: Qiita::Elasticsearch::Nodes::FilterQueryNode

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

Constant Summary collapse

DEFAULT_HIERARCHAL_FIELDS =
[]

Instance Method Summary collapse

Constructor Details

#initialize(token, hierarchal_fields: nil) ⇒ FilterQueryNode



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

def initialize(token, hierarchal_fields: nil)
  @hierarchal_fields = hierarchal_fields
  @token = token
end

Instance Method Details

#to_hashHash



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/qiita/elasticsearch/nodes/filter_query_node.rb', line 14

def to_hash
  if has_hierarchal_token?
    {
      "filtered" => {
        "filter" => {
          "bool" => {
            "should" => [
              {
                "prefix" => {
                  @token.field_name => @token.term + "/",
                },
              },
              {
                "term" => {
                  @token.field_name => @token.term,
                },
              },
            ],
          },
        },
        "query" => {
          "match_all" => {},
        },
      },
    }
  else
    {
      "filtered" => {
        "filter" => {
          "term" => {
            @token.field_name => @token.term,
          },
        },
        "query" => {
          "match_all" => {},
        },
      },
    }
  end
end