pixeltrix-thinking-sphinx 1.1.5 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +147 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
- data/lib/thinking_sphinx/active_record/delta.rb +14 -1
- data/lib/thinking_sphinx/active_record/scopes.rb +37 -0
- data/lib/thinking_sphinx/active_record.rb +46 -12
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +9 -1
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +3 -2
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +12 -5
- data/lib/thinking_sphinx/association.rb +20 -0
- data/lib/thinking_sphinx/attribute.rb +187 -116
- data/lib/thinking_sphinx/class_facet.rb +15 -0
- data/lib/thinking_sphinx/configuration.rb +46 -14
- data/lib/thinking_sphinx/core/string.rb +3 -10
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +3 -3
- data/lib/thinking_sphinx/deltas/default_delta.rb +9 -6
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +1 -1
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +4 -2
- data/lib/thinking_sphinx/deltas.rb +14 -6
- data/lib/thinking_sphinx/deploy/capistrano.rb +98 -0
- data/lib/thinking_sphinx/excerpter.rb +22 -0
- data/lib/thinking_sphinx/facet.rb +68 -18
- data/lib/thinking_sphinx/facet_search.rb +134 -0
- data/lib/thinking_sphinx/field.rb +7 -97
- data/lib/thinking_sphinx/index/builder.rb +255 -201
- data/lib/thinking_sphinx/index.rb +28 -343
- data/lib/thinking_sphinx/property.rb +160 -0
- data/lib/thinking_sphinx/rails_additions.rb +7 -4
- data/lib/thinking_sphinx/search.rb +593 -587
- data/lib/thinking_sphinx/search_methods.rb +421 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
- data/lib/thinking_sphinx/source/sql.rb +128 -0
- data/lib/thinking_sphinx/source.rb +150 -0
- data/lib/thinking_sphinx/tasks.rb +45 -11
- data/lib/thinking_sphinx.rb +88 -14
- data/rails/init.rb +14 -0
- data/spec/{unit → lib}/thinking_sphinx/active_record/delta_spec.rb +7 -7
- data/spec/{unit → lib}/thinking_sphinx/active_record/has_many_association_spec.rb +0 -0
- data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +92 -0
- data/spec/{unit → lib}/thinking_sphinx/active_record_spec.rb +115 -42
- data/spec/{unit → lib}/thinking_sphinx/association_spec.rb +4 -5
- data/spec/lib/thinking_sphinx/attribute_spec.rb +465 -0
- data/spec/{unit → lib}/thinking_sphinx/configuration_spec.rb +118 -7
- data/spec/{unit → lib}/thinking_sphinx/core/string_spec.rb +0 -0
- data/spec/lib/thinking_sphinx/excerpter_spec.rb +49 -0
- data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
- data/spec/lib/thinking_sphinx/facet_spec.rb +302 -0
- data/spec/{unit → lib}/thinking_sphinx/field_spec.rb +26 -17
- data/spec/lib/thinking_sphinx/index/builder_spec.rb +355 -0
- data/spec/{unit → lib}/thinking_sphinx/index/faux_column_spec.rb +0 -0
- data/spec/{unit → lib}/thinking_sphinx/index_spec.rb +3 -12
- data/spec/lib/thinking_sphinx/rails_additions_spec.rb +191 -0
- data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
- data/spec/lib/thinking_sphinx/search_spec.rb +887 -0
- data/spec/lib/thinking_sphinx/source_spec.rb +217 -0
- data/spec/{unit → lib}/thinking_sphinx_spec.rb +30 -8
- data/tasks/distribution.rb +20 -1
- data/tasks/testing.rb +7 -15
- data/vendor/after_commit/init.rb +3 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +27 -4
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +1 -1
- data/vendor/after_commit/lib/after_commit.rb +4 -1
- data/vendor/riddle/lib/riddle/client/message.rb +4 -3
- data/vendor/riddle/lib/riddle/client.rb +3 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +8 -2
- data/vendor/riddle/lib/riddle/controller.rb +1 -1
- data/vendor/riddle/lib/riddle.rb +1 -1
- metadata +75 -39
- data/README +0 -107
- data/lib/thinking_sphinx/active_record/search.rb +0 -57
- data/lib/thinking_sphinx/collection.rb +0 -142
- data/lib/thinking_sphinx/facet_collection.rb +0 -44
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +0 -107
- data/spec/unit/thinking_sphinx/attribute_spec.rb +0 -212
- data/spec/unit/thinking_sphinx/collection_spec.rb +0 -14
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +0 -5
- data/spec/unit/thinking_sphinx/search_spec.rb +0 -59
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::SearchMethods do
|
4
|
+
it "should be included into models with indexes" do
|
5
|
+
Alpha.included_modules.should include(ThinkingSphinx::SearchMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should not be included into models that don't have indexes" do
|
9
|
+
Gamma.included_modules.should_not include(ThinkingSphinx::SearchMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.search_context' do
|
13
|
+
it "should return nil if not within a model" do
|
14
|
+
ThinkingSphinx.search_context.should be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return the model if within one" do
|
18
|
+
Alpha.search_context.should == Alpha
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.search' do
|
23
|
+
it "should return an instance of ThinkingSphinx::Search" do
|
24
|
+
Alpha.search.class.should == ThinkingSphinx::Search
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should set the classes option if not already set" do
|
28
|
+
search = Alpha.search
|
29
|
+
search.options[:classes].should == [Alpha]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "shouldn't set the classes option if already defined" do
|
33
|
+
search = Alpha.search :classes => [Beta]
|
34
|
+
search.options[:classes].should == [Beta]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should default to nil for the classes options" do
|
38
|
+
ThinkingSphinx.search.options[:classes].should be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.search_for_ids' do
|
43
|
+
it "should return an instance of ThinkingSphinx::Search" do
|
44
|
+
Alpha.search.class.should == ThinkingSphinx::Search
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set the classes option if not already set" do
|
48
|
+
search = Alpha.search_for_ids
|
49
|
+
search.options[:classes].should == [Alpha]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "shouldn't set the classes option if already defined" do
|
53
|
+
search = Alpha.search_for_ids :classes => [Beta]
|
54
|
+
search.options[:classes].should == [Beta]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set ids_only to true" do
|
58
|
+
search = Alpha.search_for_ids
|
59
|
+
search.options[:ids_only].should be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.search_for_id' do
|
64
|
+
before :each do
|
65
|
+
@config = ThinkingSphinx::Configuration.instance
|
66
|
+
@client = Riddle::Client.new
|
67
|
+
|
68
|
+
@config.stub!(:client => @client)
|
69
|
+
@client.stub!(:query => {:matches => [], :total_found => 0})
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should set the id range to the given id value" do
|
73
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core')
|
74
|
+
|
75
|
+
@client.id_range.should == (101..101)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not make any calls to the database" do
|
79
|
+
Alpha.should_not_receive(:find)
|
80
|
+
|
81
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core', :classes => [Alpha])
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return true if there is a record" do
|
85
|
+
@client.stub!(:query => {:matches => [
|
86
|
+
{:attributes => {'sphinx_internal_id' => 100}}
|
87
|
+
], :total_found => 1})
|
88
|
+
|
89
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core').should be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return false if there isn't a record" do
|
93
|
+
ThinkingSphinx.search_for_id(101, 'alpha_core').should be_false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '.count' do
|
98
|
+
before :each do
|
99
|
+
@config = ThinkingSphinx::Configuration.instance
|
100
|
+
@client = Riddle::Client.new
|
101
|
+
|
102
|
+
@config.stub!(:client => @client)
|
103
|
+
@client.stub!(:query => {:matches => [], :total_found => 42})
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should fall through to ActiveRecord if called on a class" do
|
107
|
+
@client.should_not_receive(:query)
|
108
|
+
|
109
|
+
Alpha.count
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return the total number of results if called globally" do
|
113
|
+
ThinkingSphinx.count.should == 42
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.search_count' do
|
118
|
+
before :each do
|
119
|
+
@config = ThinkingSphinx::Configuration.instance
|
120
|
+
@client = Riddle::Client.new
|
121
|
+
|
122
|
+
@config.stub!(:client => @client)
|
123
|
+
@client.stub!(:query => {:matches => [], :total_found => 42})
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return the total number of results" do
|
127
|
+
Alpha.search_count.should == 42
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should not make any calls to the database" do
|
131
|
+
Alpha.should_not_receive(:find)
|
132
|
+
|
133
|
+
Alpha.search_count
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '.facets' do
|
138
|
+
it "should return a FacetSearch instance" do
|
139
|
+
Alpha.facets.should be_a(ThinkingSphinx::FacetSearch)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should set the classes option if not already set" do
|
143
|
+
facets = Alpha.facets
|
144
|
+
facets.options[:classes].should == [Alpha]
|
145
|
+
end
|
146
|
+
|
147
|
+
it "shouldn't set the classes option if already defined" do
|
148
|
+
facets = Alpha.facets :classes => [Beta]
|
149
|
+
facets.options[:classes].should == [Beta]
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|