This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'sunspot_rails' | |
gem 'sunspot_solr' # optional pre-packaged Solr distribution for use in development |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# citi is the stem of cities | |
citi => city | |
# copi is the stem of copies | |
copi => copy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Product.where("name LIKE '%?%'", 'cities').all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductsController < ApplicationController | |
def search | |
Product.search do | |
fulltext 'cities' | |
with :used, false | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
artist_keys = REDIS.smembers('users:1') | |
artist_keys.map!{ |artist_id| "artists:#{artist_id}" } #=> ["artists:1", "artists:2", "artists:3"] | |
REDIS.sinter(*artist_keys) #=> ["2","3"] where 2 and 3 are user IDs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REDIS.smembers('artists:1') #=> ["1","2","3"] where 1, 2 and 3 are user IDs | |
REDIS.smembers('users:1') #=> ["1","2","3"] where 1, 2 and 3 are artist IDs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post '/interests' do | |
# Connect to Redis | |
uri = URI.parse(ENV["REDIS_URL"] || 'redis://localhost:6379') | |
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password) | |
# Parse the JSON body | |
join = JSON.parse(request.body.read) | |
# Register the user's interest in an artist | |
REDIS.sadd("artists:#{join['artist_id']}", join['user_id']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'services/user' | |
require 'services/artist' | |
describe 'POST /interests' do | |
# Use User and Artist Ruby wrappers to call services | |
let(:user) { Services::User.create(:name => 'Mike Pack') } | |
let(:artist) { Services::Artist.create(:name => 'Cool Band', :genres => ['Jazz', 'R&B']) } | |
it 'registers a users interest in an artist' do | |
# Initiate POST request |