Module: Workarea::Search::AdminIndexSearch
- Extended by:
- ActiveSupport::Concern
- Included in:
- AdminAssets, AdminCategories, AdminDiscounts, AdminFulfillmentSkus, AdminInventorySkus, AdminOrders, AdminPages, AdminPaymentTransactions, AdminPricingSkus, AdminProducts, AdminReleasables, AdminReleases, AdminSearch, AdminSegments, AdminUsers
- Defined in:
- app/queries/workarea/search/admin_index_search.rb
Instance Method Summary collapse
- #aggregations ⇒ Object
- #autocomplete? ⇒ Boolean
- #exclude_filter_clause ⇒ Object
- #facets ⇒ Object
- #fields ⇒ Object
- #filters ⇒ Object
- #jump_to_navigation_filter_clause ⇒ Object
- #post_filter ⇒ Object
- #query ⇒ Object
- #sanitized_query ⇒ Object
Instance Method Details
#aggregations ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 74 def aggregations results = facets.map(&:aggregation).reduce(&:merge) return results unless results['type'].present? agg = if results['type'][:terms].present? results['type'] elsif results['type'][:aggs].present? && results['type'][:aggs]['type'].present? results['type'][:aggs]['type'] end agg[:terms][:size] = 50 agg[:terms][:order] = { _term: 'asc' } results end |
#autocomplete? ⇒ Boolean
10 11 12 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 10 def autocomplete? !!params[:autocomplete] end |
#exclude_filter_clause ⇒ Object
103 104 105 106 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 103 def exclude_filter_clause return {} unless params[:exclude_ids].present? { bool: { must_not: { terms: { _id: Array(params[:exclude_ids]) } } } } end |
#facets ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 117 def facets @facets ||= [ TermsFacet.new(self, 'type'), TermsFacet.new(self, 'status'), TermsFacet.new(self, 'tags'), TermsFacet.new(self, 'upcoming_changes'), TermsFacet.new(self, 'active_by_segment') ] end |
#fields ⇒ Object
14 15 16 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 14 def fields %w(search_text jump_to_text jump_to_search_text) end |
#filters ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 108 def filters @filters ||= [ DateFilter.new(self, 'created_at', :gte), DateFilter.new(self, 'created_at', :lte), DateFilter.new(self, 'updated_at', :gte), DateFilter.new(self, 'updated_at', :lte) ] end |
#jump_to_navigation_filter_clause ⇒ Object
99 100 101 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 99 def { exists: { field: :jump_to_param } } end |
#post_filter ⇒ Object
91 92 93 94 95 96 97 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 91 def post_filter { bool: { must: facets.map(&:post_filter_clause).reject(&:blank?) } } end |
#query ⇒ Object
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 18 def query filter_clauses = [ filters.map(&:query_clause).reject(&:blank?), exclude_filter_clause, ].flatten if sanitized_query.blank? { bool: { must: filter_clauses } } elsif autocomplete? { bool: { must: filter_clauses + [ { match_phrase_prefix: { jump_to_search_text: { query: sanitized_query, max_expansions: 10 } } } ] } } else { bool: { must: filter_clauses + [ { bool: { should: [ { query_string: { query: sanitized_query, fields: fields, use_dis_max: true } }, { match: { keywords: { query: params[:q].downcase, type: 'phrase', boost: 999 } } } ] } } ] } } end end |
#sanitized_query ⇒ Object
6 7 8 |
# File 'app/queries/workarea/search/admin_index_search.rb', line 6 def sanitized_query @sanitized_query ||= QueryString.new(params[:q]).sanitized end |