Created
October 19, 2009 18:26
-
-
Save royw/213584 to your computer and use it in GitHub Desktop.
This file contains 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 'mongo_mapper' | |
require 'spec' | |
MongoMapper.connection = Mongo::Connection.new('localhost') | |
MongoMapper.database = 'tmp' | |
class Book | |
include MongoMapper::Document | |
key :title, String | |
key :_keywords, Array, :index => true | |
before_save do |record| | |
record._keywords = record.title.split(' ').uniq | |
end | |
end | |
describe "testing text search" do | |
before :each do | |
Book.collection.clear | |
book = Book.create :title => 'Something Wicked This Way Comes' | |
book = Book.create :title => 'The Dragonriders of Pern' | |
book = Book.create :title => "Starpilot's Grave" | |
book = Book.create :title => "The Man Who Sold The Moon" | |
book = Book.create :title => "The Man With The Golden Gun" | |
puts "\n:_keywords => " + book._keywords.inspect | |
end | |
it "should allow combining search results" do | |
a = Book.all(:conditions => {:_keywords => ['Man', 'Grave']}) | |
b = Book.all(:conditions => {:_keywords => 'The'}) | |
a.size.should == 3 | |
b.size.should == 3 | |
c = (a + b).uniq | |
c.size.should == 4 # fails with result 6 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment