Skip to content

Instantly share code, notes, and snippets.

gem 'sunspot_rails'
gem 'sunspot_solr' # optional pre-packaged Solr distribution for use in development
# citi is the stem of cities
citi => city
# copi is the stem of copies
copi => copy
Product.where("name LIKE '%?%'", 'cities').all
class ProductsController < ApplicationController
def search
Product.search do
fulltext 'cities'
with :used, false
end
end
end
@mikepack
mikepack / gist:1854515
Created February 17, 2012 17:34
Test Nomenclature

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
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
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'])
@mikepack
mikepack / interest_spec.rb
Created February 12, 2012 20:01
interest_spec.rb
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