Skip to content

Instantly share code, notes, and snippets.

@redox
Forked from ArunGupta25/Listing.rb
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redox/e1f994400c1cb6f34d05 to your computer and use it in GitHub Desktop.
Save redox/e1f994400c1cb6f34d05 to your computer and use it in GitHub Desktop.
Listing.reindex!
class Listing < ActiveRecord::Base
include AlgoliaSearch
algoliasearch per_environment: true, if: :saleable do
attribute :title, :designer, :price, :description, :size, :category, :price_drops, :dropped, :price_updated_at, :created_at, :cover_photo, :images_processed, :bumped_at, :location, :strata, :retina_cover_photo, :retina_cover_height, :retina_cover_width, :followerno
attributesToIndex ['unordered(designer)', 'unordered(title)', 'unordered(description)', 'category', 'size', 'price']
customRanking ['desc(price_updated_at)']
ranking ['custom', 'desc(followerno)', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact']
synonyms [
["footwear", "shoes"],
["bottoms", "pants"],
["outerwear", "jacket"]
]
add_slave 'Listing_by_date_added', per_environment: true do
customRanking ['desc(created_at)']
ranking ['custom', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact']
end
add_slave 'Listing_by_followers', per_environment: true do
customRanking ['desc(created_at)']
ranking ['desc(followerno)', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact', 'custom']
end
add_slave 'Listing_by_high_price', per_environment: true do
ranking ['desc(price)', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact', 'desc(followerno)']
end
add_slave 'Listing_by_low_price', per_environment: true do
ranking ['asc(price)', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact', 'desc(followerno)']
end
end
def saleable
self.sold == nil && self.images_processed == true && ['grailed',nil].include?(self.strata) && [false,nil].include?(self.deleted)
end
def saleable_changed?
self.sold_changed? || self.images_processed_changed? || self.strata_changed? || self.deleted_changed?
end
end
--- !ruby/ActiveRecord:Listing
attributes:
id: 61431
user_id: 2
title: hello there
created_at: 2015-02-11 03:06:09.172737000 Z
updated_at: 2015-02-11 03:06:13.324638000 Z
designer: A.P.C.
price: 22.0
description: hello
size: '34'
category: bottoms
sold:
paypal_id: ryz0n89@gmail.com
sold_price:
sold_at:
color:
buyer_id:
price_drops: []
dropped:
price_updated_at: 2015-02-11 03:06:09.172737000 Z
cover_photo: http://assets1.grailed.com/uploads/photo/image/289972/display_upload_2F1423623967192-2efw2ikevu7919k9-43fb48f4f7a6ef13bd117a6a2cfef6d4_2F.jpeg
images_processed: true
buynow: false
makeoffer: true
shipto: ''
shipcost:
bumped_at: 2015-02-11 03:06:09.172192000 Z
location: United Kingdom
strata: grailed
deleted:
deleted_at:
followerno: 0
repost:
repost_id:
refresh:
retina_cover_photo: http://assets3.grailed.com/uploads/photo/image/289972/showpage_upload_2F1423623967192-2efw2ikevu7919k9-43fb48f4f7a6ef13bd117a6a2cfef6d4_2F.jpeg
retina_cover_width: 306
retina_cover_height: 306
currency: USD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment