Class: Workarea::Search::Storefront

Inherits:
Object
  • Object
show all
Includes:
Elasticsearch::Document
Defined in:
app/models/workarea/search/storefront.rb,
app/models/workarea/search/storefront/page.rb,
app/models/workarea/search/storefront/search.rb,
app/models/workarea/search/storefront/product.rb,
app/models/workarea/search/storefront/category.rb,
app/models/workarea/search/storefront/product/text.rb,
app/models/workarea/search/storefront/category_query.rb,
app/models/workarea/search/storefront/product/facets.rb,
app/models/workarea/search/storefront/product/pricing.rb,
app/models/workarea/search/storefront/product/sorting.rb,
app/models/workarea/search/storefront/product/analytics.rb,
app/models/workarea/search/storefront/product/inventory.rb,
app/models/workarea/search/storefront/product/categories.rb

Direct Known Subclasses

Category, Page, Product, Search

Defined Under Namespace

Classes: Category, CategoryQuery, Page, Product, Search

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Elasticsearch::Document

all, #as_bulk_document, current_index_prefix, #destroy, #initialize, #save

Class Method Details

.ensure_dynamic_mappingsObject



6
7
8
9
10
11
12
13
# File 'app/models/workarea/search/storefront.rb', line 6

def self.ensure_dynamic_mappings
  # This ensures a bare-bones product mapping in Elasticsearch, which is
  # required for some functionality (e.g. categories in percolator).
  #
  # If there haven't been any products created, the mappings required for a
  # query or percolator may not be there.
  ensure_product_mappings
end

.ensure_product_mappingsObject



15
16
17
18
19
20
21
# File 'app/models/workarea/search/storefront.rb', line 15

def self.ensure_product_mappings
  product = Workarea::Search::Storefront::Product.new(
    Workarea::Catalog::Product.new(id: 'null_product')
  )
  product.save
  Storefront.delete(product.id)
end

Instance Method Details

#activeObject

Whether the product is active. Stored as ‘:now` way for upgrade support to v3.5 without requiring reindexing.

return [Hash]



45
46
47
# File 'app/models/workarea/search/storefront.rb', line 45

def active
  { now: model.active? }
end

#active_segment_idsObject



49
50
51
# File 'app/models/workarea/search/storefront.rb', line 49

def active_segment_ids
  model.try(:active_segment_ids)
end

#as_documentObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/workarea/search/storefront.rb', line 81

def as_document
  Release.with_current(release_id) do
    {
      id: id,
      type: type,
      slug: slug,
      active: active,
      active_segment_ids: active_segment_ids,
      release_id: release_id,
      changeset_release_ids: Array.wrap(model.try(:changesets)).map(&:release_id),
      suggestion_content: suggestion_content,
      created_at: model.created_at,
      updated_at: model.updated_at,
      facets: facets,
      numeric: numeric,
      keywords: keywords,
      sorts: sorts,
      content: content,
      cache: cache
    }
  end
end

#cacheObject



73
74
75
# File 'app/models/workarea/search/storefront.rb', line 73

def cache
  {}
end

#contentObject



69
70
71
# File 'app/models/workarea/search/storefront.rb', line 69

def content
  {}
end

#facetsObject



53
54
55
# File 'app/models/workarea/search/storefront.rb', line 53

def facets
  {}
end

#idObject



23
24
25
26
# File 'app/models/workarea/search/storefront.rb', line 23

def id
  pieces = [type, model.id, model.try(:release_id)].reject(&:blank?)
  CGI.escape(pieces.join('-'))
end

#keywordsObject



61
62
63
# File 'app/models/workarea/search/storefront.rb', line 61

def keywords
  {}
end

#numericObject



57
58
59
# File 'app/models/workarea/search/storefront.rb', line 57

def numeric
  {}
end

#release_idObject



36
37
38
# File 'app/models/workarea/search/storefront.rb', line 36

def release_id
  model.try(:release_id).presence || 'live'
end

#slugObject



32
33
34
# File 'app/models/workarea/search/storefront.rb', line 32

def slug
  model.slug
end

#sortsObject



65
66
67
# File 'app/models/workarea/search/storefront.rb', line 65

def sorts
  {}
end

#suggestion_contentObject



77
78
79
# File 'app/models/workarea/search/storefront.rb', line 77

def suggestion_content
  nil
end

#typeObject



28
29
30
# File 'app/models/workarea/search/storefront.rb', line 28

def type
  model.class.name.demodulize.underscore
end