Class: CustomAttributes::SearchQuery
- Inherits:
-
Object
- Object
- CustomAttributes::SearchQuery
- Defined in:
- lib/custom_attributes/search_query.rb
Overview
Builds a query in elastic search DSL
Instance Attribute Summary collapse
-
#customizable ⇒ Object
Returns the value of attribute customizable.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#field_list ⇒ Object
Returns the value of attribute field_list.
-
#filter_by ⇒ Object
Returns the value of attribute filter_by.
-
#filter_by_delimiter ⇒ Object
Returns the value of attribute filter_by_delimiter.
-
#filter_or ⇒ Object
Returns the value of attribute filter_or.
-
#filter_or_delimiter ⇒ Object
Returns the value of attribute filter_or_delimiter.
-
#match_any ⇒ Object
Returns the value of attribute match_any.
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#query ⇒ Object
fulltext search query, by default applied to all fields.
-
#sort_by ⇒ Object
Returns the value of attribute sort_by.
Instance Method Summary collapse
Instance Attribute Details
#customizable ⇒ Object
Returns the value of attribute customizable.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def customizable @customizable end |
#defaults ⇒ Object
Returns the value of attribute defaults.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def defaults @defaults end |
#field_list ⇒ Object
Returns the value of attribute field_list.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def field_list @field_list end |
#filter_by ⇒ Object
Returns the value of attribute filter_by.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def filter_by @filter_by end |
#filter_by_delimiter ⇒ Object
Returns the value of attribute filter_by_delimiter.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def filter_by_delimiter @filter_by_delimiter end |
#filter_or ⇒ Object
Returns the value of attribute filter_or.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def filter_or @filter_or end |
#filter_or_delimiter ⇒ Object
Returns the value of attribute filter_or_delimiter.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def filter_or_delimiter @filter_or_delimiter end |
#match_any ⇒ Object
Returns the value of attribute match_any.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def match_any @match_any end |
#page ⇒ Object
Returns the value of attribute page.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def per_page @per_page end |
#query ⇒ Object
fulltext search query, by default applied to all fields
22 23 24 |
# File 'lib/custom_attributes/search_query.rb', line 22 def query @query end |
#sort_by ⇒ Object
Returns the value of attribute sort_by.
6 7 8 |
# File 'lib/custom_attributes/search_query.rb', line 6 def sort_by @sort_by end |
Instance Method Details
#build ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/custom_attributes/search_query.rb', line 8 def build { query: subquery, from: from, size: per_page, sort: sort_hash_to_array } end |
#default_fields ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/custom_attributes/search_query.rb', line 69 def default_fields default_fields = { custom_fields: Hash[customizable.available_custom_fields .select { |cf| cf.searchable == true } .map { |cf| [cf.slug.to_sym, {}] }] } if customizable.present? default_fields[:fields] = Hash[ customizable.class.default_fields.map { |f| [f.to_sym, {}] } ] end default_fields end |
#from ⇒ Object
17 18 19 |
# File 'lib/custom_attributes/search_query.rb', line 17 def from (page - 1) * per_page end |
#match_any? ⇒ Boolean
65 66 67 |
# File 'lib/custom_attributes/search_query.rb', line 65 def match_any? @match_any end |