outoftime-sunspot 0.0.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/README.rdoc +26 -33
- data/TODO +7 -0
- data/VERSION.yml +2 -2
- data/lib/light_config.rb +5 -5
- data/lib/sunspot/adapters.rb +209 -33
- data/lib/sunspot/configuration.rb +25 -10
- data/lib/sunspot/dsl/fields.rb +42 -11
- data/lib/sunspot/dsl/query.rb +150 -6
- data/lib/sunspot/dsl/scope.rb +16 -26
- data/lib/sunspot/facet.rb +37 -0
- data/lib/sunspot/facet_row.rb +34 -0
- data/lib/sunspot/facets.rb +21 -0
- data/lib/sunspot/field.rb +112 -56
- data/lib/sunspot/indexer.rb +49 -46
- data/lib/sunspot/query.rb +217 -49
- data/lib/sunspot/restriction.rb +158 -14
- data/lib/sunspot/search.rb +79 -28
- data/lib/sunspot/session.rb +75 -8
- data/lib/sunspot/setup.rb +171 -0
- data/lib/sunspot/type.rb +116 -32
- data/lib/sunspot/util.rb +141 -7
- data/lib/sunspot.rb +260 -31
- data/spec/api/build_search_spec.rb +139 -33
- data/spec/api/indexer_spec.rb +33 -2
- data/spec/api/search_retrieval_spec.rb +85 -2
- data/spec/api/session_spec.rb +14 -6
- data/spec/integration/faceting_spec.rb +39 -0
- data/spec/integration/keyword_search_spec.rb +1 -1
- data/spec/integration/scoped_search_spec.rb +175 -0
- data/spec/mocks/mock_adapter.rb +7 -10
- data/spec/mocks/post.rb +7 -2
- data/tasks/rdoc.rake +7 -0
- data/tasks/spec.rake +3 -0
- data/tasks/todo.rake +4 -0
- metadata +12 -7
- data/lib/sunspot/builder.rb +0 -78
- data/spec/api/standard_search_builder_spec.rb +0 -76
- data/spec/custom_expectation.rb +0 -53
- data/spec/integration/field_types_spec.rb +0 -62
@@ -1,76 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe 'standard search builder' do
|
4
|
-
before :each do
|
5
|
-
stub_results
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should give access to order through hash and object' do
|
9
|
-
search = session.search(Post, :order => 'sort_title asc')
|
10
|
-
search.builder.params[:order].should == 'sort_title asc'
|
11
|
-
search.builder.order.should == 'sort_title asc'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should give nil order if no order set' do
|
15
|
-
search = session.search(Post)
|
16
|
-
search.builder.params.should have_key(:order)
|
17
|
-
search.builder.params[:order].should be_nil
|
18
|
-
search.builder.order.should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should give access to page and per-page through hash and object' do
|
22
|
-
search = session.search(Post, :page => 2, :per_page => 15)
|
23
|
-
search.builder.params[:page].should == 2
|
24
|
-
search.builder.params[:per_page].should == 15
|
25
|
-
search.builder.page.should == 2
|
26
|
-
search.builder.per_page.should == 15
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should give access to keywords' do
|
30
|
-
search = session.search(Post, :keywords => 'some keywords')
|
31
|
-
search.builder.params[:keywords].should == 'some keywords'
|
32
|
-
search.builder.keywords.should == 'some keywords'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should have nil keywords if no keywords given' do
|
36
|
-
search = session.search(Post)
|
37
|
-
search.builder.params.should have_key(:keywords)
|
38
|
-
search.builder.params[:keywords].should be_nil
|
39
|
-
search.builder.keywords.should be_nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should give access to conditions' do
|
43
|
-
search = session.search(Post, :conditions => { :blog_id => 1 })
|
44
|
-
search.builder.params[:conditions][:blog_id].should == 1
|
45
|
-
search.builder.conditions.blog_id.should == 1
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should have nil values for fields with unspecified conditions' do
|
49
|
-
search = session.search(Post)
|
50
|
-
%w(title blog_id category_ids average_rating published_at sort_title).each do |field_name|
|
51
|
-
search.builder.params[:conditions].should have_key(field_name.to_sym)
|
52
|
-
search.builder.params[:conditions][field_name.to_sym].should == nil
|
53
|
-
search.builder.conditions.should respond_to(field_name)
|
54
|
-
search.builder.conditions.send(field_name).should == nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def stub_results(*results)
|
61
|
-
response = mock('response', :hits => [], :total_hits => 0)
|
62
|
-
connection.stub!(:query).and_return(response)
|
63
|
-
end
|
64
|
-
|
65
|
-
def config
|
66
|
-
@config ||= Sunspot::Configuration.build
|
67
|
-
end
|
68
|
-
|
69
|
-
def connection
|
70
|
-
@connection ||= mock('connection')
|
71
|
-
end
|
72
|
-
|
73
|
-
def session
|
74
|
-
@session ||= Sunspot::Session.new(config, connection)
|
75
|
-
end
|
76
|
-
end
|
data/spec/custom_expectation.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
module Matchy
|
2
|
-
module Expectations
|
3
|
-
class HaveKeyExpectation < Base
|
4
|
-
def matches?(receiver)
|
5
|
-
@receiver = receiver
|
6
|
-
receiver.has_key?(@expected)
|
7
|
-
end
|
8
|
-
|
9
|
-
def failure_message
|
10
|
-
"Expected #{@receiver.inspect} to have key #{@expected.inspect}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def negative_failure_message
|
14
|
-
"Expected #{@receiver.inspect} not to have key #{@expected.inspect}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class BooleanExpectation < Base
|
19
|
-
def initialize(method, args, test_case)
|
20
|
-
@method = method
|
21
|
-
@args = args
|
22
|
-
@test_case = test_case
|
23
|
-
end
|
24
|
-
|
25
|
-
def matches?(receiver)
|
26
|
-
@receiver = receiver
|
27
|
-
receiver.send("#{@method}?", *@args)
|
28
|
-
end
|
29
|
-
|
30
|
-
def failure_message
|
31
|
-
"Expected #{@receiver} to #{'be ' if @args.empty?}#{@method}#{@args.map { |arg| arg.inspect } * ', '}"
|
32
|
-
end
|
33
|
-
|
34
|
-
def negative_failure_message
|
35
|
-
"Expected #{@receiver} to not #{'be ' if @args.empty?}#{@method}#{@args.map { |arg| arg.inspect } * ', '}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module TestCaseExtensions
|
40
|
-
def have_key(key)
|
41
|
-
Matchy::Expectations::HaveKeyExpectation.new(key, self)
|
42
|
-
end
|
43
|
-
|
44
|
-
def method_missing(method, *args, &block)
|
45
|
-
if match = /be_(.*)/.match(method.to_s)
|
46
|
-
Matchy::Expectations::BooleanExpectation.new(match[1], [], self)
|
47
|
-
else
|
48
|
-
Matchy::Expectations::BooleanExpectation.new(method.to_s, args, self)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe 'field types' do
|
4
|
-
def self.test_field_type(name, field, *values)
|
5
|
-
raise(ArgumentError, 'Please supply five values') unless values.length == 5
|
6
|
-
|
7
|
-
context "with field of type #{name}" do
|
8
|
-
before :all do
|
9
|
-
Sunspot.remove_all
|
10
|
-
@posts = values.map do |value|
|
11
|
-
post = Post.new(field => value)
|
12
|
-
Sunspot.index(post)
|
13
|
-
post
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should filter by exact match' do
|
18
|
-
Sunspot.search(Post) { with.send(field, values[2]) }.results.should == [@posts[2]]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should filter by less than' do
|
22
|
-
results = Sunspot.search(Post) { with.send(field).less_than values[2] }.results
|
23
|
-
(0..2).each { |i| results.should include(@posts[i]) }
|
24
|
-
(3..4).each { |i| results.should_not include(@posts[i]) }
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should filter by greater than' do
|
28
|
-
results = Sunspot.search(Post) { with.send(field).greater_than values[2] }.results
|
29
|
-
(2..4).each { |i| results.should include(@posts[i]) }
|
30
|
-
(0..1).each { |i| results.should_not include(@posts[i]) }
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should filter by between' do
|
34
|
-
results = Sunspot.search(Post) { with.send(field).between(values[1]..values[3]) }.results
|
35
|
-
(1..3).each { |i| results.should include(@posts[i]) }
|
36
|
-
[0, 4].each { |i| results.should_not include(@posts[i]) }
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should filter by any of' do
|
40
|
-
results = Sunspot.search(Post) { with.send(field).any_of(values.values_at(1, 3)) }.results
|
41
|
-
[1, 3].each { |i| results.should include(@posts[i]) }
|
42
|
-
[0, 2, 4].each { |i| results.should_not include(@posts[i]) }
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should order by field ascending' do
|
46
|
-
results = Sunspot.search(Post) { order_by field, :asc }.results
|
47
|
-
results.should == @posts
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should order by field descending' do
|
51
|
-
results = Sunspot.search(Post) { order_by field, :desc }.results
|
52
|
-
results.should == @posts.reverse
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
test_field_type 'String', :title, 'apple', 'banana', 'cherry', 'date', 'eggplant'
|
58
|
-
test_field_type 'Integer', :blog_id, -2, 0, 3, 12, 20
|
59
|
-
test_field_type 'Float', :average_rating, -2.5, 0.0, 3.2, 3.5, 16.0
|
60
|
-
test_field_type 'Time', :published_at, *(['1970-01-01 00:00:00 UTC', '1983-07-08 04:00:00 UTC', '1983-07-08 02:00:00 -0500',
|
61
|
-
'2005-11-05 10:00:00 UTC', Time.now.to_s].map { |t| Time.parse(t) })
|
62
|
-
end
|