Sha256: 97a8dd7b625977fa92603edd9d833919a8e00ffdf2a5f8d12487cb9ddc0db069
Contents?: true
Size: 1.01 KB
Versions: 5
Compression:
Stored size: 1.01 KB
Contents
module Workarea decorate BulkIndexProducts, with: :browse_option do class_methods do def perform(ids = Catalog::Product.pluck(:id)) ids = ids.map { |id| BrowseOptionIds.extract(id) }.uniq super(ids) end def perform_by_models(products) return if products.blank? delete_existing_documents(products) super end private def delete_existing_documents(products) I18n.for_each_locale do ids = products.map do |product| id = Search::Storefront::Product.new(product).keywords[:catalog_id] id.gsub(Workarea.config.search_index_id_escape_regex) { |match| "\\#{match}" } end query = { query: { terms: { 'keywords.catalog_id': ids } } } hits = Search::Storefront.search(query)['hits']['hits'] documents = hits.map do |hit| { id: hit['_source']['id'], bulk_action: :delete } end Search::Storefront.bulk(documents) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems