Skip to content

Instantly share code, notes, and snippets.

@ArunGupta25
Created February 12, 2015 22:38
Show Gist options
  • Save ArunGupta25/56fc4df01b878c30a8fe to your computer and use it in GitHub Desktop.
Save ArunGupta25/56fc4df01b878c30a8fe to your computer and use it in GitHub Desktop.
class Listing < ActiveRecord::Base
include AlgoliaSearch
include ListingSearch
end
module ListingSearch
def listing_search
algoliasearch per_environment: true, if: :saleable? do
attribute :price_i do
price.to_i
end
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, :price_i
indexable_attributes = ['unordered(designer)', 'unordered(title)', 'unordered(description)', 'category', 'size']
attributesToIndex indexable_attributes
attribute :price_i do
price.to_i
end
customRanking ['desc(price_updated_at)']
ranking ['typo', 'geo', 'words', 'proximity', 'attribute', 'exact', 'custom', 'desc(followerno)']
synonyms [
["footwear", "shoes"],
["bottoms", "pants"],
["outerwear", "jacket"]
]
add_slave 'Listing_by_date_added', per_environment: true do
attributesToIndex indexable_attributes
customRanking ['desc(created_at)']
ranking ['typo', 'geo', 'words', 'proximity', 'attribute', 'exact', 'custom']
end
add_slave 'Listing_by_followers', per_environment: true do
attributesToIndex indexable_attributes
customRanking ['desc(price_updated_at)']
ranking ['desc(followerno)', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact', 'custom']
end
add_slave 'Listing_by_high_price', per_environment: true do
attributesToIndex indexable_attributes
customRanking ['desc(price_updated_at)']
ranking ['desc(price_i)', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact']
end
add_slave 'Listing_by_low_price', per_environment: true do
attributesToIndex indexable_attributes
customRanking ['desc(price_updated_at)']
ranking ['asc(price_i)', 'typo', 'geo', 'words', 'proximity', 'attribute', 'exact']
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment