<commit_before>class ProductsIndex < Chewy::Index
  define_type Spree::Product.includes(:taxons, :master, :prices, {:product_properties => :property}) do
    field :name
    field :description
    field :image_url, type: 'string', value: ->(product){ product.image && product.image.attachment.url(:listing) }
    field :price, type: 'float', value: ->(product){ product.price.to_f }
    field :slug, type: 'string'
    field :facet_properties, type: 'object', value: ->(product){ product.facet_properties }
    field :taxons, value: ->(product){
      taxons = []
      product.taxons.map{|t| taxons.push(*t.self_and_ancestors.map(&:id))}
      taxons.uniq
    }
    field :taxon_positions, type: 'object', value: ->(product){
      positions = {}
      product.taxons.select('spree_taxons.id, spree_products_taxons.position').map{|t| positions[t.id] = t.position }
      positions
    }
    # Locations is disabled out the box but can be added with the following:
    # field :location, type: 'geo_point', value: ->(product){ product.location }<commit_msg>fixed product pricing<commit_after>class ProductsIndex < Chewy::Index
  define_type Spree::Product.includes(:taxons, :master, :prices, {:product_properties => :property}) do
    field :name
    field :description
    field :image_url, type: 'string', value: ->(product){ product.image && product.image.attachment.url(:listing) }
    field :price, type: 'float', value: ->(product){ product.master.price.to_f }
    field :slug, type: 'string'
    field :facet_properties, type: 'object', value: ->(product){ product.facet_properties }
    field :taxons, value: ->(product){
      taxons = []
      product.taxons.map{|t| taxons.push(*t.self_and_ancestors.map(&:id))}
      taxons.uniq
    }
    field :taxon_positions, type: 'object', value: ->(product){
      positions = {}
      product.taxons.select('spree_taxons.id, spree_products_taxons.position').map{|t| positions[t.id] = t.position }
      positions
    }
    # Locations is disabled out the box but can be added with the following:
    # field :location, type: 'geo_point', value: ->(product){ product.location }
{'fraction_non_alphanumeric': 0.15265382808830436, 'fraction_numerical': 0.0, 'mean_word_length': 4.023584905660377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2944527', 'n_tokens_mistral': 675, 'n_tokens_neox': 666, 'n_words': 162}