Module: Workarea::Search::ProductDisplayRules
- Extended by:
- ActiveSupport::Concern
- Included in:
- CategoryBrowse, ProductSearch, RelatedProducts
- Defined in:
- app/queries/workarea/search/product_display_rules.rb
Instance Method Summary collapse
- #active_for_segments_clause ⇒ Object
- #displayable_when_out_of_stock_sort_clause ⇒ Object
- #inventory_display_clause(allow_displayable_when_out_of_stock: true) ⇒ Object
- #preview_current_release_clause ⇒ Object
- #product_display_query_clauses(allow_displayable_when_out_of_stock: true) ⇒ Object
Instance Method Details
#active_for_segments_clause ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/queries/workarea/search/product_display_rules.rb', line 40 def active_for_segments_clause { bool: { must: [ { term: { 'active.now' => true } }, { bool: { should: [ { bool: { must_not: { exists: { field: 'active_segment_ids' } } } }, { terms: { 'active_segment_ids' => Segment.current.map(&:id) } } ] } } ] } } end |
#displayable_when_out_of_stock_sort_clause ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'app/queries/workarea/search/product_display_rules.rb', line 18 def displayable_when_out_of_stock_sort_clause { 'sorts.inventory_score': { order: 'desc', missing: '_first', unmapped_type: 'float' } } end |
#inventory_display_clause(allow_displayable_when_out_of_stock: true) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/queries/workarea/search/product_display_rules.rb', line 28 def inventory_display_clause(allow_displayable_when_out_of_stock: true) result = { bool: { should: [{ range: { 'numeric.inventory': { gt: 0 } } }] } } if allow_displayable_when_out_of_stock result[:bool][:should] << { term: { 'facets.inventory_policies': 'displayable_when_out_of_stock' } } end result end |
#preview_current_release_clause ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/queries/workarea/search/product_display_rules.rb', line 58 def preview_current_release_clause if Release.current.blank? { bool: { minimum_should_match: 1, should: [ { term: { release_id: 'live' } }, { bool: { must_not: { exists: { field: 'release_id' } } } } # for upgrade compatiblity ] } } else { bool: { minimum_should_match: 1, should: [ { term: { release_id: Release.current.id } }, { bool: { must_not: [{ term: { changeset_release_ids: Release.current.id } }], must: [ { bool: { minimum_should_match: 1, should: [ { term: { release_id: 'live' } }, { bool: { must_not: { exists: { field: 'release_id' } } } } # for upgrade compatiblity ] } } ] } } ] } } end end |
#product_display_query_clauses(allow_displayable_when_out_of_stock: true) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/queries/workarea/search/product_display_rules.rb', line 6 def product_display_query_clauses(allow_displayable_when_out_of_stock: true) [ { term: { type: 'product' } }, { range: { "numeric.variant_count": { gt: 0 } } }, inventory_display_clause( allow_displayable_when_out_of_stock: allow_displayable_when_out_of_stock ), active_for_segments_clause, preview_current_release_clause ] end |