Class: Caoutsearch::Filter::Match
- Inherits:
-
Base
- Object
- Base
- Caoutsearch::Filter::Match
show all
- Defined in:
- lib/caoutsearch/filter/match.rb
Constant Summary
collapse
- QUERY_STRING_REGEXP =
%r{
(?:[*?][^\s*?]|[^\s*?][*?]|(?:^|\s)(?:AND|OR|NOT)(?:$|\s)|^\*$)
}x
- STRIPPED_OPERATOR_REGEXP =
%r{
(?:^\s*(?:AND|OR)\*$|^\s*(?:AND|OR)\s+|\s+(?:AND|OR)\s*$)
}x
Instance Attribute Summary
Attributes inherited from Base
#key, #options, #original_value, #type
Instance Method Summary
collapse
Methods inherited from Base
#as_json, call, #initialize, #value
Instance Method Details
#filter ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/caoutsearch/filter/match.rb', line 6
def filter
if use_query_string?
{
simple_query_string: {
fields: [key],
query: sanitized_for_query_string,
default_operator: "and",
analyze_wildcard: true
}
}
elsif multiple_words?
{match: {key => {query: value, operator: "and"}}}
else
{match: {key => value}}
end
end
|
#multiple_words? ⇒ Boolean
27
28
29
|
# File 'lib/caoutsearch/filter/match.rb', line 27
def multiple_words?
value.is_a?(String) && value.squish.include?(" ")
end
|
#nested_query? ⇒ Boolean
23
24
25
|
# File 'lib/caoutsearch/filter/match.rb', line 23
def nested_query?
nested_path? && (multiple_words? || !include_in_parent?)
end
|
#sanitized_for_query_string ⇒ Object
#use_query_string? ⇒ Boolean
41
42
43
|
# File 'lib/caoutsearch/filter/match.rb', line 41
def use_query_string?
QUERY_STRING_REGEXP.match?(value)
end
|