muck-solr 0.4.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/CHANGE_LOG +239 -0
- data/LICENSE +19 -0
- data/README.markdown +118 -0
- data/README.rdoc +107 -0
- data/Rakefile +99 -0
- data/TESTING_THE_PLUGIN +25 -0
- data/VERSION.yml +4 -0
- data/config/solr.yml +15 -0
- data/config/solr_environment.rb +32 -0
- data/lib/acts_as_solr.rb +65 -0
- data/lib/acts_as_solr/acts_methods.rb +352 -0
- data/lib/acts_as_solr/class_methods.rb +236 -0
- data/lib/acts_as_solr/common_methods.rb +89 -0
- data/lib/acts_as_solr/deprecation.rb +61 -0
- data/lib/acts_as_solr/instance_methods.rb +165 -0
- data/lib/acts_as_solr/lazy_document.rb +18 -0
- data/lib/acts_as_solr/parser_methods.rb +203 -0
- data/lib/acts_as_solr/search_results.rb +68 -0
- data/lib/acts_as_solr/solr_fixtures.rb +13 -0
- data/lib/acts_as_solr/tasks.rb +10 -0
- data/lib/acts_as_solr/tasks/database.rake +16 -0
- data/lib/acts_as_solr/tasks/solr.rake +135 -0
- data/lib/acts_as_solr/tasks/test.rake +5 -0
- data/lib/solr.rb +26 -0
- data/lib/solr/connection.rb +177 -0
- data/lib/solr/document.rb +75 -0
- data/lib/solr/exception.rb +13 -0
- data/lib/solr/field.rb +36 -0
- data/lib/solr/importer.rb +19 -0
- data/lib/solr/importer/array_mapper.rb +26 -0
- data/lib/solr/importer/delimited_file_source.rb +38 -0
- data/lib/solr/importer/hpricot_mapper.rb +27 -0
- data/lib/solr/importer/mapper.rb +51 -0
- data/lib/solr/importer/solr_source.rb +41 -0
- data/lib/solr/importer/xpath_mapper.rb +35 -0
- data/lib/solr/indexer.rb +52 -0
- data/lib/solr/request.rb +26 -0
- data/lib/solr/request/add_document.rb +58 -0
- data/lib/solr/request/base.rb +36 -0
- data/lib/solr/request/commit.rb +29 -0
- data/lib/solr/request/delete.rb +48 -0
- data/lib/solr/request/dismax.rb +46 -0
- data/lib/solr/request/index_info.rb +22 -0
- data/lib/solr/request/modify_document.rb +46 -0
- data/lib/solr/request/optimize.rb +19 -0
- data/lib/solr/request/ping.rb +36 -0
- data/lib/solr/request/select.rb +54 -0
- data/lib/solr/request/spellcheck.rb +30 -0
- data/lib/solr/request/standard.rb +402 -0
- data/lib/solr/request/update.rb +23 -0
- data/lib/solr/response.rb +27 -0
- data/lib/solr/response/add_document.rb +17 -0
- data/lib/solr/response/base.rb +42 -0
- data/lib/solr/response/commit.rb +15 -0
- data/lib/solr/response/delete.rb +13 -0
- data/lib/solr/response/dismax.rb +8 -0
- data/lib/solr/response/index_info.rb +26 -0
- data/lib/solr/response/modify_document.rb +17 -0
- data/lib/solr/response/optimize.rb +14 -0
- data/lib/solr/response/ping.rb +26 -0
- data/lib/solr/response/ruby.rb +42 -0
- data/lib/solr/response/select.rb +17 -0
- data/lib/solr/response/spellcheck.rb +20 -0
- data/lib/solr/response/standard.rb +60 -0
- data/lib/solr/response/xml.rb +39 -0
- data/lib/solr/solrtasks.rb +27 -0
- data/lib/solr/util.rb +32 -0
- data/lib/solr/xml.rb +44 -0
- data/solr/CHANGES.txt +1207 -0
- data/solr/LICENSE.txt +712 -0
- data/solr/NOTICE.txt +90 -0
- data/solr/etc/jetty.xml +205 -0
- data/solr/etc/webdefault.xml +379 -0
- data/solr/lib/easymock.jar +0 -0
- data/solr/lib/jetty-6.1.3.jar +0 -0
- data/solr/lib/jetty-util-6.1.3.jar +0 -0
- data/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
- data/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
- data/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
- data/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
- data/solr/lib/servlet-api-2.4.jar +0 -0
- data/solr/lib/servlet-api-2.5-6.1.3.jar +0 -0
- data/solr/lib/xpp3-1.1.3.4.O.jar +0 -0
- data/solr/solr/README.txt +52 -0
- data/solr/solr/bin/abc +176 -0
- data/solr/solr/bin/abo +176 -0
- data/solr/solr/bin/backup +108 -0
- data/solr/solr/bin/backupcleaner +142 -0
- data/solr/solr/bin/commit +128 -0
- data/solr/solr/bin/optimize +129 -0
- data/solr/solr/bin/readercycle +129 -0
- data/solr/solr/bin/rsyncd-disable +77 -0
- data/solr/solr/bin/rsyncd-enable +76 -0
- data/solr/solr/bin/rsyncd-start +145 -0
- data/solr/solr/bin/rsyncd-stop +105 -0
- data/solr/solr/bin/scripts-util +83 -0
- data/solr/solr/bin/snapcleaner +148 -0
- data/solr/solr/bin/snapinstaller +168 -0
- data/solr/solr/bin/snappuller +248 -0
- data/solr/solr/bin/snappuller-disable +77 -0
- data/solr/solr/bin/snappuller-enable +77 -0
- data/solr/solr/bin/snapshooter +109 -0
- data/solr/solr/conf/admin-extra.html +31 -0
- data/solr/solr/conf/protwords.txt +21 -0
- data/solr/solr/conf/schema.xml +126 -0
- data/solr/solr/conf/scripts.conf +24 -0
- data/solr/solr/conf/solrconfig.xml +458 -0
- data/solr/solr/conf/stopwords.txt +57 -0
- data/solr/solr/conf/synonyms.txt +31 -0
- data/solr/solr/conf/xslt/example.xsl +132 -0
- data/solr/solr/conf/xslt/example_atom.xsl +63 -0
- data/solr/solr/conf/xslt/example_rss.xsl +62 -0
- data/solr/start.jar +0 -0
- data/solr/webapps/solr.war +0 -0
- data/test/config/solr.yml +2 -0
- data/test/db/connections/mysql/connection.rb +10 -0
- data/test/db/connections/sqlite/connection.rb +8 -0
- data/test/db/migrate/001_create_books.rb +15 -0
- data/test/db/migrate/002_create_movies.rb +12 -0
- data/test/db/migrate/003_create_categories.rb +11 -0
- data/test/db/migrate/004_create_electronics.rb +16 -0
- data/test/db/migrate/005_create_authors.rb +12 -0
- data/test/db/migrate/006_create_postings.rb +9 -0
- data/test/db/migrate/007_create_posts.rb +13 -0
- data/test/db/migrate/008_create_gadgets.rb +11 -0
- data/test/fixtures/authors.yml +9 -0
- data/test/fixtures/books.yml +13 -0
- data/test/fixtures/categories.yml +7 -0
- data/test/fixtures/db_definitions/mysql.sql +41 -0
- data/test/fixtures/electronics.yml +49 -0
- data/test/fixtures/movies.yml +9 -0
- data/test/fixtures/postings.yml +10 -0
- data/test/functional/acts_as_solr_test.rb +413 -0
- data/test/functional/association_indexing_test.rb +37 -0
- data/test/functional/faceted_search_test.rb +163 -0
- data/test/functional/multi_solr_search_test.rb +57 -0
- data/test/models/author.rb +10 -0
- data/test/models/book.rb +10 -0
- data/test/models/category.rb +8 -0
- data/test/models/electronic.rb +25 -0
- data/test/models/gadget.rb +9 -0
- data/test/models/movie.rb +17 -0
- data/test/models/novel.rb +2 -0
- data/test/models/post.rb +3 -0
- data/test/models/posting.rb +11 -0
- data/test/test_helper.rb +54 -0
- data/test/unit/acts_methods_shoulda.rb +68 -0
- data/test/unit/class_methods_shoulda.rb +85 -0
- data/test/unit/common_methods_shoulda.rb +111 -0
- data/test/unit/instance_methods_shoulda.rb +318 -0
- data/test/unit/lazy_document_shoulda.rb +34 -0
- data/test/unit/parser_instance.rb +19 -0
- data/test/unit/parser_methods_shoulda.rb +268 -0
- data/test/unit/solr_instance.rb +49 -0
- data/test/unit/test_helper.rb +24 -0
- metadata +241 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
|
2
|
+
|
|
3
|
+
class UserModel; end
|
|
4
|
+
|
|
5
|
+
class LazyDocumentTest < Test::Unit::TestCase
|
|
6
|
+
context "With a lazy document" do
|
|
7
|
+
setup do
|
|
8
|
+
@record = stub(:record)
|
|
9
|
+
@record.stubs(:is_valid?).returns true
|
|
10
|
+
UserModel.stubs(:find).returns @record
|
|
11
|
+
@document = ActsAsSolr::LazyDocument.new(1, UserModel)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "with an uninitialized document" do
|
|
15
|
+
should "fetch the record from the database" do
|
|
16
|
+
UserModel.expects(:find).with(1).returns(@record)
|
|
17
|
+
@document.is_valid?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "with an initialized document" do
|
|
22
|
+
should "not fetch the record again" do
|
|
23
|
+
@document.is_valid?
|
|
24
|
+
@document.expects(:find).never
|
|
25
|
+
@document.is_valid?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "reroute the calls to the record" do
|
|
29
|
+
@record.expects(:is_valid?).once
|
|
30
|
+
@document.is_valid?
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class ActsAsSolr::ParserInstance
|
|
2
|
+
include ActsAsSolr::ParserMethods
|
|
3
|
+
include ActsAsSolr::CommonMethods
|
|
4
|
+
attr_accessor :configuration, :solr_configuration
|
|
5
|
+
|
|
6
|
+
def table_name
|
|
7
|
+
"documents"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def primary_key
|
|
11
|
+
"id"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def find(*args)
|
|
15
|
+
[]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
public :parse_results, :reorder, :parse_query, :add_scores, :replace_types
|
|
19
|
+
end
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
|
2
|
+
|
|
3
|
+
class ActsAsSolr::Post; end
|
|
4
|
+
|
|
5
|
+
class ParserMethodsTest < Test::Unit::TestCase
|
|
6
|
+
|
|
7
|
+
context "With a parser instance" do
|
|
8
|
+
setup do
|
|
9
|
+
@parser = ActsAsSolr::ParserInstance.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "When parsing results" do
|
|
13
|
+
setup do
|
|
14
|
+
@results = stub(:results)
|
|
15
|
+
@results.stubs(:total_hits).returns(2)
|
|
16
|
+
@results.stubs(:hits).returns([])
|
|
17
|
+
@results.stubs(:max_score).returns 2.1
|
|
18
|
+
@results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}})
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should "return a SearchResults object" do
|
|
22
|
+
assert_equal ActsAsSolr::SearchResults, @parser.parse_results(@results).class
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
should "set the max score" do
|
|
26
|
+
assert_equal 2.1, @parser.parse_results(@results).max_score
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
should "include the facets" do
|
|
30
|
+
@results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}, "facet_counts" => 2})
|
|
31
|
+
assert_equal 2, @parser.parse_results(@results, :facets => true).facets
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "when the format requests objects" do
|
|
35
|
+
setup do
|
|
36
|
+
@parser.configuration = {:format => :objects}
|
|
37
|
+
@parser.solr_configuration = {:primary_key_field => :pk_id}
|
|
38
|
+
@results.stubs(:hits).returns [{"pk_id" => 1}, {"pk_id" => 2}]
|
|
39
|
+
@parser.stubs(:reorder)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
should "query with the record ids" do
|
|
43
|
+
@parser.expects(:find).with(:all, :conditions => ["documents.id in (?)", [1, 2]]).returns [1, 2]
|
|
44
|
+
@parser.parse_results(@results)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
should "reorder the records" do
|
|
48
|
+
@parser.expects(:reorder).with([], [1, 2])
|
|
49
|
+
@parser.parse_results(@results)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
should "add :include if :include was specified" do
|
|
53
|
+
@parser.expects(:find).with(:all, :conditions => ["documents.id in (?)", [1, 2]], :include => [:author]).returns [1, 2]
|
|
54
|
+
@parser.parse_results(@results, :include => [:author])
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context "when the format doesn't request objects" do
|
|
59
|
+
setup do
|
|
60
|
+
@parser.solr_configuration = {:primary_key_field => "pk_id"}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
should "not query the database" do
|
|
64
|
+
@parser.expects(:find).never
|
|
65
|
+
@parser.parse_results(@results, :format => nil)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
should "return just the ids" do
|
|
69
|
+
@results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}])
|
|
70
|
+
assert_equal [1, 2], @parser.parse_results(@results, :format => nil).docs
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
should "ignore the :lazy option" do
|
|
74
|
+
@results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}])
|
|
75
|
+
assert_equal [1, 2], @parser.parse_results(@results, :format => :ids, :lazy => true).docs
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context "with an empty result set" do
|
|
80
|
+
setup do
|
|
81
|
+
@results.stubs(:total_hits).returns(0)
|
|
82
|
+
@results.stubs(:hits).returns([])
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
should "return an empty search results set" do
|
|
86
|
+
assert_equal 0, @parser.parse_results(@results).total
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should "not have any search results" do
|
|
90
|
+
assert_equal [], @parser.parse_results(@results).docs
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
context "with a nil result set" do
|
|
95
|
+
should "return an empty search results set" do
|
|
96
|
+
assert_equal 0, @parser.parse_results(nil).total
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "with the scores option" do
|
|
101
|
+
should "add the scores" do
|
|
102
|
+
@parser.expects(:add_scores).with([], @results)
|
|
103
|
+
@parser.parse_results(@results, :scores => true)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context "with lazy format" do
|
|
108
|
+
setup do
|
|
109
|
+
@parser.solr_configuration = {:primary_key_field => :pk_id}
|
|
110
|
+
@results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}])
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
should "create LazyDocuments for the resulting docs" do
|
|
114
|
+
result = @parser.parse_results(@results, :lazy => true)
|
|
115
|
+
assert_equal ActsAsSolr::LazyDocument, result.results.first.class
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
should "set the document id as the record id" do
|
|
119
|
+
result = @parser.parse_results(@results, :lazy => true)
|
|
120
|
+
assert_equal 1, result.results.first.id
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
should "set the document class" do
|
|
124
|
+
result = @parser.parse_results(@results, :lazy => true)
|
|
125
|
+
assert_equal ActsAsSolr::ParserInstance, result.results.first.clazz.class
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
context "when reordering results" do
|
|
132
|
+
should "raise an error if arguments don't have the same number of elements" do
|
|
133
|
+
assert_raise(RuntimeError) {@parser.reorder([], [1])}
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
should "reorder the results to match the order of the documents returned by solr" do
|
|
137
|
+
thing1 = stub(:thing1)
|
|
138
|
+
thing1.stubs(:id).returns 5
|
|
139
|
+
thing2 = stub(:thing2)
|
|
140
|
+
thing2.stubs(:id).returns 1
|
|
141
|
+
thing3 = stub(:things3)
|
|
142
|
+
thing3.stubs(:id).returns 3
|
|
143
|
+
things = [thing1, thing2, thing3]
|
|
144
|
+
reordered = @parser.reorder(things, [1, 3, 5])
|
|
145
|
+
assert_equal [1, 3, 5], reordered.collect{|thing| thing.id}
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
context "When parsing a query" do
|
|
150
|
+
setup do
|
|
151
|
+
ActsAsSolr::Post.stubs(:execute)
|
|
152
|
+
@parser.stubs(:solr_type_condition).returns "(type:ParserMethodsTest)"
|
|
153
|
+
@parser.solr_configuration = {:primary_key_field => "id"}
|
|
154
|
+
@parser.configuration = {:solr_fields => nil}
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
should "set the limit and offset" do
|
|
158
|
+
ActsAsSolr::Post.expects(:execute).with {|request|
|
|
159
|
+
10 == request.to_hash[:rows]
|
|
160
|
+
20 == request.to_hash[:start]
|
|
161
|
+
}
|
|
162
|
+
@parser.parse_query "foo", :limit => 10, :offset => 20
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
should "set the operator" do
|
|
166
|
+
ActsAsSolr::Post.expects(:execute).with {|request|
|
|
167
|
+
"OR" == request.to_hash["q.op"]
|
|
168
|
+
}
|
|
169
|
+
@parser.parse_query "foo", :operator => :or
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
should "not execute anything if the query is nil" do
|
|
173
|
+
ActsAsSolr::Post.expects(:execute).never
|
|
174
|
+
assert_nil @parser.parse_query(nil)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
should "not execute anything if the query is ''" do
|
|
178
|
+
ActsAsSolr::Post.expects(:execute).never
|
|
179
|
+
assert_nil @parser.parse_query('')
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
should "raise an error if invalid options where specified" do
|
|
183
|
+
assert_raise(RuntimeError) {@parser.parse_query "foo", :invalid => true}
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
should "add the type" do
|
|
187
|
+
ActsAsSolr::Post.expects(:execute).with {|request|
|
|
188
|
+
request.to_hash[:q].include?("(type:ParserMethodsTest)")
|
|
189
|
+
}
|
|
190
|
+
@parser.parse_query "foo"
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
should "append the field types for the specified fields" do
|
|
194
|
+
ActsAsSolr::Post.expects(:execute).with {|request|
|
|
195
|
+
request.to_hash[:q].include?("(username_t:Chunky)")
|
|
196
|
+
}
|
|
197
|
+
@parser.parse_query "username:Chunky"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
should "replace the field types" do
|
|
201
|
+
@parser.expects(:replace_types).returns(["active_i:1"])
|
|
202
|
+
ActsAsSolr::Post.expects(:execute).with {|request|
|
|
203
|
+
request.to_hash[:q].include?("active_i:1")
|
|
204
|
+
}
|
|
205
|
+
@parser.parse_query "active:1"
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
should "add score and primary key to field list" do
|
|
209
|
+
ActsAsSolr::Post.expects(:execute).with {|request|
|
|
210
|
+
request.to_hash[:fl] == ('id,score')
|
|
211
|
+
}
|
|
212
|
+
@parser.parse_query "foo"
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
context "with the order option" do
|
|
216
|
+
should "add the order criteria to the query" do
|
|
217
|
+
ActsAsSolr::Post.expects(:execute).with {|request|
|
|
218
|
+
request.to_hash[:q].include?(";active_t desc")
|
|
219
|
+
}
|
|
220
|
+
@parser.parse_query "active:1", :order => "active desc"
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
context "with facets" do
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
context "When setting the field types" do
|
|
229
|
+
setup do
|
|
230
|
+
@parser.configuration = {:solr_fields => {:name => {:type => :string},
|
|
231
|
+
:age => {:type => :integer}}}
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
should "replace the _t suffix with the real type" do
|
|
235
|
+
assert_equal ["name_s:Chunky AND age_i:21"], @parser.replace_types(["name_t:Chunky AND age_t:21"])
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
context "with a suffix" do
|
|
239
|
+
should "not include the colon when false" do
|
|
240
|
+
assert_equal ["name_s"], @parser.replace_types(["name_t"], false)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
should "include the colon by default" do
|
|
244
|
+
assert_equal ["name_s:Chunky"], @parser.replace_types(["name_t:Chunky"])
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
context "When adding scores" do
|
|
250
|
+
setup do
|
|
251
|
+
@solr_data = stub(:results)
|
|
252
|
+
@solr_data.stubs(:total_hits).returns(1)
|
|
253
|
+
@solr_data.stubs(:hits).returns([{"id" => 2, "score" => 2.546}])
|
|
254
|
+
@solr_data.stubs(:max_score).returns 2.1
|
|
255
|
+
|
|
256
|
+
@results = [Array.new]
|
|
257
|
+
|
|
258
|
+
@parser.stubs(:record_id).returns(2)
|
|
259
|
+
|
|
260
|
+
@parser.solr_configuration = {:primary_key_field => "id"}
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
should "add the score to the result document" do
|
|
264
|
+
assert_equal 2.546, @parser.add_scores(@results, @solr_data).first.last.solr_score
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
class SolrInstance
|
|
2
|
+
include ActsAsSolr::InstanceMethods
|
|
3
|
+
attr_accessor :configuration, :solr_configuration, :name
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
include ActsAsSolr::ActsMethods
|
|
7
|
+
include ActsAsSolr::ClassMethods
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(name = "Chunky bacon!")
|
|
11
|
+
@name = name
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.primary_key
|
|
15
|
+
"id"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def logger
|
|
19
|
+
@logger ||= Logger.new(StringIO.new)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def record_id(obj)
|
|
23
|
+
10
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def boost_rate
|
|
27
|
+
10.0
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def irate
|
|
31
|
+
8.0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def name_for_solr
|
|
35
|
+
name
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def id_for_solr
|
|
39
|
+
"bogus"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def type_for_solr
|
|
43
|
+
"humbug"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_solr_field_type(args)
|
|
47
|
+
"s"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
dir = File.dirname(__FILE__)
|
|
2
|
+
$:.unshift(File.join(File.expand_path(dir), "..", "..", "lib"))
|
|
3
|
+
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require 'acts_as_solr'
|
|
7
|
+
require 'activesupport'
|
|
8
|
+
require 'mocha'
|
|
9
|
+
require 'active_support'
|
|
10
|
+
require 'logger'
|
|
11
|
+
require File.expand_path("#{dir}/solr_instance")
|
|
12
|
+
require File.expand_path("#{dir}/parser_instance")
|
|
13
|
+
require 'erb'
|
|
14
|
+
require 'ostruct'
|
|
15
|
+
|
|
16
|
+
if RUBY_VERSION =~ /^1\.9/
|
|
17
|
+
puts "\nRunning the unit test suite doesn't as of yet work with Ruby 1.9, because Mocha hasn't yet been updated to use minitest."
|
|
18
|
+
puts
|
|
19
|
+
exit 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
require 'mocha'
|
|
23
|
+
gem 'thoughtbot-shoulda'
|
|
24
|
+
require 'shoulda'
|
metadata
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: muck-solr
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.4.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Mathias Meyer, Joel Duffin, Justin Ball
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-06-15 00:00:00 -06:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: "This gem adds full text search capabilities and many other nifty features from Apache\xEF\xBF\xBDs Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
|
|
17
|
+
email: meyer@paperplanes.de
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.markdown
|
|
25
|
+
- README.rdoc
|
|
26
|
+
files:
|
|
27
|
+
- CHANGE_LOG
|
|
28
|
+
- LICENSE
|
|
29
|
+
- README.markdown
|
|
30
|
+
- README.rdoc
|
|
31
|
+
- Rakefile
|
|
32
|
+
- TESTING_THE_PLUGIN
|
|
33
|
+
- VERSION.yml
|
|
34
|
+
- config/solr.yml
|
|
35
|
+
- config/solr_environment.rb
|
|
36
|
+
- lib/acts_as_solr.rb
|
|
37
|
+
- lib/acts_as_solr/acts_methods.rb
|
|
38
|
+
- lib/acts_as_solr/class_methods.rb
|
|
39
|
+
- lib/acts_as_solr/common_methods.rb
|
|
40
|
+
- lib/acts_as_solr/deprecation.rb
|
|
41
|
+
- lib/acts_as_solr/instance_methods.rb
|
|
42
|
+
- lib/acts_as_solr/lazy_document.rb
|
|
43
|
+
- lib/acts_as_solr/parser_methods.rb
|
|
44
|
+
- lib/acts_as_solr/search_results.rb
|
|
45
|
+
- lib/acts_as_solr/solr_fixtures.rb
|
|
46
|
+
- lib/acts_as_solr/tasks.rb
|
|
47
|
+
- lib/acts_as_solr/tasks/database.rake
|
|
48
|
+
- lib/acts_as_solr/tasks/solr.rake
|
|
49
|
+
- lib/acts_as_solr/tasks/test.rake
|
|
50
|
+
- lib/solr.rb
|
|
51
|
+
- lib/solr/connection.rb
|
|
52
|
+
- lib/solr/document.rb
|
|
53
|
+
- lib/solr/exception.rb
|
|
54
|
+
- lib/solr/field.rb
|
|
55
|
+
- lib/solr/importer.rb
|
|
56
|
+
- lib/solr/importer/array_mapper.rb
|
|
57
|
+
- lib/solr/importer/delimited_file_source.rb
|
|
58
|
+
- lib/solr/importer/hpricot_mapper.rb
|
|
59
|
+
- lib/solr/importer/mapper.rb
|
|
60
|
+
- lib/solr/importer/solr_source.rb
|
|
61
|
+
- lib/solr/importer/xpath_mapper.rb
|
|
62
|
+
- lib/solr/indexer.rb
|
|
63
|
+
- lib/solr/request.rb
|
|
64
|
+
- lib/solr/request/add_document.rb
|
|
65
|
+
- lib/solr/request/base.rb
|
|
66
|
+
- lib/solr/request/commit.rb
|
|
67
|
+
- lib/solr/request/delete.rb
|
|
68
|
+
- lib/solr/request/dismax.rb
|
|
69
|
+
- lib/solr/request/index_info.rb
|
|
70
|
+
- lib/solr/request/modify_document.rb
|
|
71
|
+
- lib/solr/request/optimize.rb
|
|
72
|
+
- lib/solr/request/ping.rb
|
|
73
|
+
- lib/solr/request/select.rb
|
|
74
|
+
- lib/solr/request/spellcheck.rb
|
|
75
|
+
- lib/solr/request/standard.rb
|
|
76
|
+
- lib/solr/request/update.rb
|
|
77
|
+
- lib/solr/response.rb
|
|
78
|
+
- lib/solr/response/add_document.rb
|
|
79
|
+
- lib/solr/response/base.rb
|
|
80
|
+
- lib/solr/response/commit.rb
|
|
81
|
+
- lib/solr/response/delete.rb
|
|
82
|
+
- lib/solr/response/dismax.rb
|
|
83
|
+
- lib/solr/response/index_info.rb
|
|
84
|
+
- lib/solr/response/modify_document.rb
|
|
85
|
+
- lib/solr/response/optimize.rb
|
|
86
|
+
- lib/solr/response/ping.rb
|
|
87
|
+
- lib/solr/response/ruby.rb
|
|
88
|
+
- lib/solr/response/select.rb
|
|
89
|
+
- lib/solr/response/spellcheck.rb
|
|
90
|
+
- lib/solr/response/standard.rb
|
|
91
|
+
- lib/solr/response/xml.rb
|
|
92
|
+
- lib/solr/solrtasks.rb
|
|
93
|
+
- lib/solr/util.rb
|
|
94
|
+
- lib/solr/xml.rb
|
|
95
|
+
- solr/CHANGES.txt
|
|
96
|
+
- solr/LICENSE.txt
|
|
97
|
+
- solr/NOTICE.txt
|
|
98
|
+
- solr/etc/jetty.xml
|
|
99
|
+
- solr/etc/webdefault.xml
|
|
100
|
+
- solr/lib/easymock.jar
|
|
101
|
+
- solr/lib/jetty-6.1.3.jar
|
|
102
|
+
- solr/lib/jetty-util-6.1.3.jar
|
|
103
|
+
- solr/lib/jsp-2.1/ant-1.6.5.jar
|
|
104
|
+
- solr/lib/jsp-2.1/core-3.1.1.jar
|
|
105
|
+
- solr/lib/jsp-2.1/jsp-2.1.jar
|
|
106
|
+
- solr/lib/jsp-2.1/jsp-api-2.1.jar
|
|
107
|
+
- solr/lib/servlet-api-2.4.jar
|
|
108
|
+
- solr/lib/servlet-api-2.5-6.1.3.jar
|
|
109
|
+
- solr/lib/xpp3-1.1.3.4.O.jar
|
|
110
|
+
- solr/solr/README.txt
|
|
111
|
+
- solr/solr/bin/abc
|
|
112
|
+
- solr/solr/bin/abo
|
|
113
|
+
- solr/solr/bin/backup
|
|
114
|
+
- solr/solr/bin/backupcleaner
|
|
115
|
+
- solr/solr/bin/commit
|
|
116
|
+
- solr/solr/bin/optimize
|
|
117
|
+
- solr/solr/bin/readercycle
|
|
118
|
+
- solr/solr/bin/rsyncd-disable
|
|
119
|
+
- solr/solr/bin/rsyncd-enable
|
|
120
|
+
- solr/solr/bin/rsyncd-start
|
|
121
|
+
- solr/solr/bin/rsyncd-stop
|
|
122
|
+
- solr/solr/bin/scripts-util
|
|
123
|
+
- solr/solr/bin/snapcleaner
|
|
124
|
+
- solr/solr/bin/snapinstaller
|
|
125
|
+
- solr/solr/bin/snappuller
|
|
126
|
+
- solr/solr/bin/snappuller-disable
|
|
127
|
+
- solr/solr/bin/snappuller-enable
|
|
128
|
+
- solr/solr/bin/snapshooter
|
|
129
|
+
- solr/solr/conf/admin-extra.html
|
|
130
|
+
- solr/solr/conf/protwords.txt
|
|
131
|
+
- solr/solr/conf/schema.xml
|
|
132
|
+
- solr/solr/conf/scripts.conf
|
|
133
|
+
- solr/solr/conf/solrconfig.xml
|
|
134
|
+
- solr/solr/conf/stopwords.txt
|
|
135
|
+
- solr/solr/conf/synonyms.txt
|
|
136
|
+
- solr/solr/conf/xslt/example.xsl
|
|
137
|
+
- solr/solr/conf/xslt/example_atom.xsl
|
|
138
|
+
- solr/solr/conf/xslt/example_rss.xsl
|
|
139
|
+
- solr/start.jar
|
|
140
|
+
- solr/webapps/solr.war
|
|
141
|
+
- test/config/solr.yml
|
|
142
|
+
- test/db/connections/mysql/connection.rb
|
|
143
|
+
- test/db/connections/sqlite/connection.rb
|
|
144
|
+
- test/db/migrate/001_create_books.rb
|
|
145
|
+
- test/db/migrate/002_create_movies.rb
|
|
146
|
+
- test/db/migrate/003_create_categories.rb
|
|
147
|
+
- test/db/migrate/004_create_electronics.rb
|
|
148
|
+
- test/db/migrate/005_create_authors.rb
|
|
149
|
+
- test/db/migrate/006_create_postings.rb
|
|
150
|
+
- test/db/migrate/007_create_posts.rb
|
|
151
|
+
- test/db/migrate/008_create_gadgets.rb
|
|
152
|
+
- test/fixtures/authors.yml
|
|
153
|
+
- test/fixtures/books.yml
|
|
154
|
+
- test/fixtures/categories.yml
|
|
155
|
+
- test/fixtures/db_definitions/mysql.sql
|
|
156
|
+
- test/fixtures/electronics.yml
|
|
157
|
+
- test/fixtures/movies.yml
|
|
158
|
+
- test/fixtures/postings.yml
|
|
159
|
+
- test/functional/acts_as_solr_test.rb
|
|
160
|
+
- test/functional/association_indexing_test.rb
|
|
161
|
+
- test/functional/faceted_search_test.rb
|
|
162
|
+
- test/functional/multi_solr_search_test.rb
|
|
163
|
+
- test/models/author.rb
|
|
164
|
+
- test/models/book.rb
|
|
165
|
+
- test/models/category.rb
|
|
166
|
+
- test/models/electronic.rb
|
|
167
|
+
- test/models/gadget.rb
|
|
168
|
+
- test/models/movie.rb
|
|
169
|
+
- test/models/novel.rb
|
|
170
|
+
- test/models/post.rb
|
|
171
|
+
- test/models/posting.rb
|
|
172
|
+
- test/test_helper.rb
|
|
173
|
+
- test/unit/acts_methods_shoulda.rb
|
|
174
|
+
- test/unit/class_methods_shoulda.rb
|
|
175
|
+
- test/unit/common_methods_shoulda.rb
|
|
176
|
+
- test/unit/instance_methods_shoulda.rb
|
|
177
|
+
- test/unit/lazy_document_shoulda.rb
|
|
178
|
+
- test/unit/parser_instance.rb
|
|
179
|
+
- test/unit/parser_methods_shoulda.rb
|
|
180
|
+
- test/unit/solr_instance.rb
|
|
181
|
+
- test/unit/test_helper.rb
|
|
182
|
+
has_rdoc: true
|
|
183
|
+
homepage: http://github.com/mattmatt/acts_as_solr
|
|
184
|
+
post_install_message:
|
|
185
|
+
rdoc_options:
|
|
186
|
+
- --charset=UTF-8
|
|
187
|
+
require_paths:
|
|
188
|
+
- lib
|
|
189
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - ">="
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
version: "0"
|
|
194
|
+
version:
|
|
195
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
|
+
requirements:
|
|
197
|
+
- - ">="
|
|
198
|
+
- !ruby/object:Gem::Version
|
|
199
|
+
version: "0"
|
|
200
|
+
version:
|
|
201
|
+
requirements: []
|
|
202
|
+
|
|
203
|
+
rubyforge_project: muck-solr
|
|
204
|
+
rubygems_version: 1.3.1
|
|
205
|
+
signing_key:
|
|
206
|
+
specification_version: 2
|
|
207
|
+
summary: "This gem adds full text search capabilities and many other nifty features from Apache\xEF\xBF\xBDs Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
|
|
208
|
+
test_files:
|
|
209
|
+
- test/db/connections/mysql/connection.rb
|
|
210
|
+
- test/db/connections/sqlite/connection.rb
|
|
211
|
+
- test/db/migrate/001_create_books.rb
|
|
212
|
+
- test/db/migrate/002_create_movies.rb
|
|
213
|
+
- test/db/migrate/003_create_categories.rb
|
|
214
|
+
- test/db/migrate/004_create_electronics.rb
|
|
215
|
+
- test/db/migrate/005_create_authors.rb
|
|
216
|
+
- test/db/migrate/006_create_postings.rb
|
|
217
|
+
- test/db/migrate/007_create_posts.rb
|
|
218
|
+
- test/db/migrate/008_create_gadgets.rb
|
|
219
|
+
- test/functional/acts_as_solr_test.rb
|
|
220
|
+
- test/functional/association_indexing_test.rb
|
|
221
|
+
- test/functional/faceted_search_test.rb
|
|
222
|
+
- test/functional/multi_solr_search_test.rb
|
|
223
|
+
- test/models/author.rb
|
|
224
|
+
- test/models/book.rb
|
|
225
|
+
- test/models/category.rb
|
|
226
|
+
- test/models/electronic.rb
|
|
227
|
+
- test/models/gadget.rb
|
|
228
|
+
- test/models/movie.rb
|
|
229
|
+
- test/models/novel.rb
|
|
230
|
+
- test/models/post.rb
|
|
231
|
+
- test/models/posting.rb
|
|
232
|
+
- test/test_helper.rb
|
|
233
|
+
- test/unit/acts_methods_shoulda.rb
|
|
234
|
+
- test/unit/class_methods_shoulda.rb
|
|
235
|
+
- test/unit/common_methods_shoulda.rb
|
|
236
|
+
- test/unit/instance_methods_shoulda.rb
|
|
237
|
+
- test/unit/lazy_document_shoulda.rb
|
|
238
|
+
- test/unit/parser_instance.rb
|
|
239
|
+
- test/unit/parser_methods_shoulda.rb
|
|
240
|
+
- test/unit/solr_instance.rb
|
|
241
|
+
- test/unit/test_helper.rb
|