acts_as_solr_reloaded 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.markdown +64 -0
- data/README.rdoc +93 -0
- data/Rakefile +71 -0
- data/TESTING_THE_PLUGIN +25 -0
- data/VERSION +1 -0
- data/config/solr.yml +14 -0
- data/config/solr_environment.rb +35 -0
- data/generators/dynamic_attributes_migration/dynamic_attributes_migration_generator.rb +7 -0
- data/generators/dynamic_attributes_migration/templates/migration.rb +15 -0
- data/generators/local_migration/local_migration_generator.rb +7 -0
- data/generators/local_migration/templates/migration.rb +16 -0
- data/lib/acts_as_solr.rb +65 -0
- data/lib/acts_as_solr/acts_methods.rb +363 -0
- data/lib/acts_as_solr/class_methods.rb +240 -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/dynamic_attribute.rb +3 -0
- data/lib/acts_as_solr/instance_methods.rb +194 -0
- data/lib/acts_as_solr/lazy_document.rb +18 -0
- data/lib/acts_as_solr/local.rb +4 -0
- data/lib/acts_as_solr/parser_methods.rb +248 -0
- data/lib/acts_as_solr/search_results.rb +74 -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 +142 -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 +406 -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 +65 -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/README.txt +36 -0
- data/solr/etc/jetty.xml +212 -0
- data/solr/etc/webdefault.xml +379 -0
- data/solr/exampledocs/books.csv +11 -0
- data/solr/exampledocs/hd.xml +46 -0
- data/solr/exampledocs/ipod_other.xml +50 -0
- data/solr/exampledocs/ipod_video.xml +35 -0
- data/solr/exampledocs/locales.xml +16 -0
- data/solr/exampledocs/mem.xml +58 -0
- data/solr/exampledocs/monitor.xml +31 -0
- data/solr/exampledocs/monitor2.xml +30 -0
- data/solr/exampledocs/mp500.xml +39 -0
- data/solr/exampledocs/post.jar +0 -0
- data/solr/exampledocs/post.sh +28 -0
- data/solr/exampledocs/sd500.xml +33 -0
- data/solr/exampledocs/solr.xml +38 -0
- data/solr/exampledocs/spellchecker.xml +58 -0
- data/solr/exampledocs/test_utf8.sh +83 -0
- data/solr/exampledocs/utf8-example.xml +42 -0
- data/solr/exampledocs/vidcard.xml +52 -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.5-6.1.3.jar +0 -0
- data/solr/multicore/README.txt +3 -0
- data/solr/multicore/core0/conf/schema.xml +41 -0
- data/solr/multicore/core0/conf/solrconfig.xml +40 -0
- data/solr/multicore/core1/conf/schema.xml +41 -0
- data/solr/multicore/core1/conf/solrconfig.xml +40 -0
- data/solr/multicore/exampledocs/ipod_other.xml +34 -0
- data/solr/multicore/exampledocs/ipod_video.xml +22 -0
- data/solr/multicore/solr.xml +35 -0
- data/solr/solr/README.txt +52 -0
- data/solr/solr/bin/abc +190 -0
- data/solr/solr/bin/abo +190 -0
- data/solr/solr/bin/backup +117 -0
- data/solr/solr/bin/backupcleaner +142 -0
- data/solr/solr/bin/commit +133 -0
- data/solr/solr/bin/optimize +134 -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 +99 -0
- data/solr/solr/bin/snapcleaner +154 -0
- data/solr/solr/bin/snapinstaller +198 -0
- data/solr/solr/bin/snappuller +269 -0
- data/solr/solr/bin/snappuller-disable +77 -0
- data/solr/solr/bin/snappuller-enable +77 -0
- data/solr/solr/bin/snapshooter +136 -0
- data/solr/solr/conf/admin-extra.html +31 -0
- data/solr/solr/conf/elevate.xml +36 -0
- data/solr/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/solr/solr/conf/protwords.txt +21 -0
- data/solr/solr/conf/schema.xml +132 -0
- data/solr/solr/conf/scripts.conf +24 -0
- data/solr/solr/conf/solrconfig.xml +906 -0
- data/solr/solr/conf/spellings.txt +2 -0
- data/solr/solr/conf/stopwords.txt +58 -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 +67 -0
- data/solr/solr/conf/xslt/example_rss.xsl +66 -0
- data/solr/solr/conf/xslt/luke.xsl +337 -0
- data/solr/solr/lib/localsolr.jar +0 -0
- data/solr/solr/lib/lucene-spatial-2.9-dev.jar +0 -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 +11 -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/db/migrate/009_create_dynamic_attributes.rb +15 -0
- data/test/db/migrate/010_create_advertises.rb +13 -0
- data/test/db/migrate/011_create_locals.rb +15 -0
- data/test/db/test.db +0 -0
- data/test/fixtures/advertises.yml +12 -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/dynamic_attributes.yml +11 -0
- data/test/fixtures/electronics.yml +49 -0
- data/test/fixtures/locals.yml +9 -0
- data/test/fixtures/movies.yml +9 -0
- data/test/fixtures/postings.yml +10 -0
- data/test/functional/acts_as_solr_test.rb +463 -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/advertise.rb +6 -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/dynamic_attribute.rb +7 -0
- data/test/models/electronic.rb +25 -0
- data/test/models/gadget.rb +9 -0
- data/test/models/local.rb +7 -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 +56 -0
- data/test/unit/acts_methods_shoulda.rb +95 -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 +372 -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 +338 -0
- data/test/unit/solr_instance.rb +74 -0
- data/test/unit/test_helper.rb +24 -0
- metadata +290 -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,338 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class ParserMethodsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "With a parser instance" do
|
6
|
+
setup do
|
7
|
+
@parser = ActsAsSolr::ParserInstance.new
|
8
|
+
end
|
9
|
+
|
10
|
+
context "When parsing results" do
|
11
|
+
setup do
|
12
|
+
@results = stub(:results)
|
13
|
+
@results.stubs(:total_hits).returns(2)
|
14
|
+
@results.stubs(:hits).returns([])
|
15
|
+
@results.stubs(:max_score).returns 2.1
|
16
|
+
@results.stubs(:highlighting).returns []
|
17
|
+
@results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}})
|
18
|
+
end
|
19
|
+
|
20
|
+
should "return a SearchResults object" do
|
21
|
+
assert_equal ActsAsSolr::SearchResults, @parser.parse_results(@results).class
|
22
|
+
end
|
23
|
+
|
24
|
+
should "set the max score" do
|
25
|
+
assert_equal 2.1, @parser.parse_results(@results).max_score
|
26
|
+
end
|
27
|
+
|
28
|
+
should "include the facets" do
|
29
|
+
@results.stubs(:data).returns({"responseHeader" => {"QTime" => "10.2"}, "facet_counts" => 2})
|
30
|
+
assert_equal 2, @parser.parse_results(@results, :facets => true).facets
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the format requests objects" do
|
34
|
+
setup do
|
35
|
+
@parser.configuration = {:format => :objects}
|
36
|
+
@parser.solr_configuration = {:primary_key_field => :pk_id}
|
37
|
+
@results.stubs(:hits).returns [{"pk_id" => 1}, {"pk_id" => 2}]
|
38
|
+
@parser.stubs(:reorder)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "query with the record ids" do
|
42
|
+
@parser.expects(:find).with(:all, :conditions => ["documents.id in (?)", [1, 2]]).returns [1, 2]
|
43
|
+
@parser.parse_results(@results)
|
44
|
+
end
|
45
|
+
|
46
|
+
should "reorder the records" do
|
47
|
+
@parser.expects(:reorder).with([], [1, 2])
|
48
|
+
@parser.parse_results(@results)
|
49
|
+
end
|
50
|
+
|
51
|
+
should "add :include if :include was specified" do
|
52
|
+
@parser.expects(:find).with(:all, :conditions => ["documents.id in (?)", [1, 2]], :include => [:author]).returns [1, 2]
|
53
|
+
@parser.parse_results(@results, :include => [:author])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when the format doesn't request objects" do
|
58
|
+
setup do
|
59
|
+
@parser.solr_configuration = {:primary_key_field => "pk_id"}
|
60
|
+
end
|
61
|
+
|
62
|
+
should "not query the database" do
|
63
|
+
@parser.expects(:find).never
|
64
|
+
@parser.parse_results(@results, :format => nil)
|
65
|
+
end
|
66
|
+
|
67
|
+
should "return just the ids" do
|
68
|
+
@results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}])
|
69
|
+
assert_equal [1, 2], @parser.parse_results(@results, :format => nil).docs
|
70
|
+
end
|
71
|
+
|
72
|
+
should "ignore the :lazy option" do
|
73
|
+
@results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}])
|
74
|
+
assert_equal [1, 2], @parser.parse_results(@results, :format => :ids, :lazy => true).docs
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "with an empty result set" do
|
79
|
+
setup do
|
80
|
+
@results.stubs(:total_hits).returns(0)
|
81
|
+
@results.stubs(:hits).returns([])
|
82
|
+
end
|
83
|
+
|
84
|
+
should "return an empty search results set" do
|
85
|
+
assert_equal 0, @parser.parse_results(@results).total
|
86
|
+
end
|
87
|
+
|
88
|
+
should "not have any search results" do
|
89
|
+
assert_equal [], @parser.parse_results(@results).docs
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "with a nil result set" do
|
94
|
+
should "return an empty search results set" do
|
95
|
+
assert_equal 0, @parser.parse_results(nil).total
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "with the scores option" do
|
100
|
+
should "add the scores" do
|
101
|
+
@parser.expects(:add_scores).with([], @results)
|
102
|
+
@parser.parse_results(@results, :scores => true)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "with lazy format" do
|
107
|
+
setup do
|
108
|
+
@parser.solr_configuration = {:primary_key_field => :pk_id}
|
109
|
+
@results.stubs(:hits).returns([{"pk_id" => 1}, {"pk_id" => 2}])
|
110
|
+
end
|
111
|
+
|
112
|
+
should "create LazyDocuments for the resulting docs" do
|
113
|
+
result = @parser.parse_results(@results, :lazy => true)
|
114
|
+
assert_equal ActsAsSolr::LazyDocument, result.results.first.class
|
115
|
+
end
|
116
|
+
|
117
|
+
should "set the document id as the record id" do
|
118
|
+
result = @parser.parse_results(@results, :lazy => true)
|
119
|
+
assert_equal 1, result.results.first.id
|
120
|
+
end
|
121
|
+
|
122
|
+
should "set the document class" do
|
123
|
+
result = @parser.parse_results(@results, :lazy => true)
|
124
|
+
assert_equal ActsAsSolr::ParserInstance, result.results.first.clazz.class
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
context "when reordering results" do
|
131
|
+
should "raise an error if arguments don't have the same number of elements" do
|
132
|
+
assert_raise(RuntimeError) {@parser.reorder([], [1])}
|
133
|
+
end
|
134
|
+
|
135
|
+
should "reorder the results to match the order of the documents returned by solr" do
|
136
|
+
thing1 = stub(:thing1)
|
137
|
+
thing1.stubs(:id).returns 5
|
138
|
+
thing2 = stub(:thing2)
|
139
|
+
thing2.stubs(:id).returns 1
|
140
|
+
thing3 = stub(:things3)
|
141
|
+
thing3.stubs(:id).returns 3
|
142
|
+
things = [thing1, thing2, thing3]
|
143
|
+
reordered = @parser.reorder(things, [1, 3, 5])
|
144
|
+
assert_equal [1, 3, 5], reordered.collect{|thing| thing.id}
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "When parsing a query" do
|
149
|
+
setup do
|
150
|
+
ActsAsSolr::Post.stubs(:execute)
|
151
|
+
@parser.stubs(:solr_type_condition).returns "(type:ParserMethodsTest)"
|
152
|
+
@parser.solr_configuration = {:primary_key_field => "id"}
|
153
|
+
@parser.configuration = {:solr_fields => nil}
|
154
|
+
end
|
155
|
+
|
156
|
+
should "set the limit and offset" do
|
157
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
158
|
+
10 == request.to_hash[:rows]
|
159
|
+
20 == request.to_hash[:start]
|
160
|
+
}
|
161
|
+
@parser.parse_query "foo", :limit => 10, :offset => 20
|
162
|
+
end
|
163
|
+
|
164
|
+
should "set the relevancy of the specified fields and non-filtered terms" do
|
165
|
+
expected = "(aeroplane brasil continent_t:south OR description_t:(aeroplane brasil)^3 OR tag_t:(aeroplane brasil)^5)"
|
166
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
167
|
+
request.to_hash[:q].starts_with? expected
|
168
|
+
}
|
169
|
+
@parser.parse_query "aeroplane brasil continent:south", :relevance => {:tag => 5, :description => 3}
|
170
|
+
end
|
171
|
+
|
172
|
+
should "set the relevance unless no query specified" do
|
173
|
+
expected = "(continent_t:south)"
|
174
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
175
|
+
request.to_hash[:q].starts_with? expected
|
176
|
+
}
|
177
|
+
@parser.parse_query "continent:south", :relevance => {:tag => 5, :description => 3}
|
178
|
+
end
|
179
|
+
|
180
|
+
should "set the relevance with simple queries" do
|
181
|
+
expected = "(car OR description_t:(car)^3 OR tag_t:(car)^5)"
|
182
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
183
|
+
request.to_hash[:q].starts_with? expected
|
184
|
+
}
|
185
|
+
@parser.parse_query "car", :relevance => {:tag => 5, :description => 3}
|
186
|
+
end
|
187
|
+
|
188
|
+
should "not execute anything if the query is nil" do
|
189
|
+
ActsAsSolr::Post.expects(:execute).never
|
190
|
+
assert_nil @parser.parse_query(nil)
|
191
|
+
end
|
192
|
+
|
193
|
+
should "not execute anything if the query is ''" do
|
194
|
+
ActsAsSolr::Post.expects(:execute).never
|
195
|
+
assert_nil @parser.parse_query('')
|
196
|
+
end
|
197
|
+
|
198
|
+
should "raise an error if invalid options where specified" do
|
199
|
+
assert_raise(RuntimeError) {@parser.parse_query "foo", :invalid => true}
|
200
|
+
end
|
201
|
+
|
202
|
+
should "add the type" do
|
203
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
204
|
+
request.to_hash[:q].include?("(type:ParserMethodsTest)")
|
205
|
+
}
|
206
|
+
@parser.parse_query "foo"
|
207
|
+
end
|
208
|
+
|
209
|
+
should "append the field types for the specified fields" do
|
210
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
211
|
+
request.to_hash[:q].include?("(username_t:Chunky)")
|
212
|
+
}
|
213
|
+
@parser.parse_query "username:Chunky"
|
214
|
+
end
|
215
|
+
|
216
|
+
should "replace the field types" do
|
217
|
+
@parser.expects(:replace_types).returns(["active_i:1"])
|
218
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
219
|
+
request.to_hash[:q].include?("active_i:1")
|
220
|
+
}
|
221
|
+
@parser.parse_query "active:1"
|
222
|
+
end
|
223
|
+
|
224
|
+
should "add score and primary key to field list" do
|
225
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
226
|
+
request.to_hash[:fl] == ('id,score')
|
227
|
+
}
|
228
|
+
@parser.parse_query "foo"
|
229
|
+
end
|
230
|
+
|
231
|
+
should "add highlight options" do
|
232
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
233
|
+
request.to_hash[:hl] == "true"
|
234
|
+
request.to_hash["hl.fl"] == "title_t"
|
235
|
+
}
|
236
|
+
@parser.parse_query "car", :highlight => {:fields => "title"}
|
237
|
+
end
|
238
|
+
|
239
|
+
should "set the operator" do
|
240
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
241
|
+
"OR" == request.to_hash["q.op"]
|
242
|
+
}
|
243
|
+
@parser.parse_query "foo", :operator => :or
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
context "with the around option" do
|
248
|
+
should "set the qt as geo" do
|
249
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
250
|
+
request.to_hash[:qt] == ('geo')
|
251
|
+
}
|
252
|
+
@parser.parse_query "foo" , :around => {:latitude => '-39.36',
|
253
|
+
:longitude => '77.4027',
|
254
|
+
:radius => 1}
|
255
|
+
end
|
256
|
+
|
257
|
+
should "set the radius" do
|
258
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
259
|
+
request.to_hash[:radius] == 12
|
260
|
+
}
|
261
|
+
@parser.parse_query "foo" , :around => {:latitude => '-39.36',
|
262
|
+
:longitude => '77.4027',
|
263
|
+
:radius => 12}
|
264
|
+
end
|
265
|
+
|
266
|
+
should "set the latitude" do
|
267
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
268
|
+
request.to_hash[:lat] == '-39.36'
|
269
|
+
}
|
270
|
+
@parser.parse_query "foo" , :around => {:latitude => '-39.36',
|
271
|
+
:longitude => '77.4027',
|
272
|
+
:radius => 12}
|
273
|
+
end
|
274
|
+
|
275
|
+
should "set the longitude" do
|
276
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
277
|
+
request.to_hash[:long] == '77.4027'
|
278
|
+
}
|
279
|
+
@parser.parse_query "foo" , :around => {:latitude => '-39.36',
|
280
|
+
:longitude => '77.4027',
|
281
|
+
:radius => 12}
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "with the order option" do
|
286
|
+
should "add the order criteria to the query" do
|
287
|
+
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
288
|
+
request.to_hash[:sort].include?("active_t desc")
|
289
|
+
}
|
290
|
+
@parser.parse_query "active:1", :order => "active desc"
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
context "with facets" do
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "When setting the field types" do
|
299
|
+
setup do
|
300
|
+
@parser.configuration = {:solr_fields => {:name => {:type => :string},
|
301
|
+
:age => {:type => :integer}}}
|
302
|
+
end
|
303
|
+
|
304
|
+
should "replace the _t suffix with the real type" do
|
305
|
+
assert_equal ["name_s:Chunky AND age_i:21"], @parser.replace_types(["name_t:Chunky AND age_t:21"])
|
306
|
+
end
|
307
|
+
|
308
|
+
context "with a suffix" do
|
309
|
+
should "not include the colon when false" do
|
310
|
+
assert_equal ["name_s"], @parser.replace_types(["name_t"], false)
|
311
|
+
end
|
312
|
+
|
313
|
+
should "include the colon by default" do
|
314
|
+
assert_equal ["name_s:Chunky"], @parser.replace_types(["name_t:Chunky"])
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context "When adding scores" do
|
320
|
+
setup do
|
321
|
+
@solr_data = stub(:results)
|
322
|
+
@solr_data.stubs(:total_hits).returns(1)
|
323
|
+
@solr_data.stubs(:hits).returns([{"id" => 2, "score" => 2.546}])
|
324
|
+
@solr_data.stubs(:max_score).returns 2.1
|
325
|
+
|
326
|
+
@results = [Array.new]
|
327
|
+
|
328
|
+
@parser.stubs(:record_id).returns(2)
|
329
|
+
|
330
|
+
@parser.solr_configuration = {:primary_key_field => "id"}
|
331
|
+
end
|
332
|
+
|
333
|
+
should "add the score to the result document" do
|
334
|
+
assert_equal 2.546, @parser.add_scores(@results, @solr_data).first.last.solr_score
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
@@ -0,0 +1,74 @@
|
|
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
|
50
|
+
|
51
|
+
class Tagging
|
52
|
+
attr_reader :tag
|
53
|
+
|
54
|
+
def initialize(name)
|
55
|
+
@tag = Tag.new name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Tag
|
60
|
+
attr_reader :name
|
61
|
+
|
62
|
+
def initialize(name)
|
63
|
+
@name = name
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Local
|
68
|
+
attr_reader :longitude, :latitude
|
69
|
+
|
70
|
+
def initialize(long, lati)
|
71
|
+
@longitude = long
|
72
|
+
@latitude = lati
|
73
|
+
end
|
74
|
+
end
|