acts_as_solr_reloaded 1.1.0 → 1.2.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/VERSION +1 -1
- data/lib/acts_as_solr.rb +4 -1
- data/lib/acts_as_solr/acts_methods.rb +17 -7
- data/lib/acts_as_solr/common_methods.rb +0 -2
- data/lib/acts_as_solr/instance_methods.rb +9 -7
- data/lib/acts_as_solr/mongo_mapper.rb +27 -0
- data/lib/acts_as_solr/parser_methods.rb +4 -5
- data/test/db/test.db +0 -0
- data/test/functional/acts_as_solr_test.rb +9 -3
- data/test/models/document.rb +6 -0
- data/test/test_helper.rb +4 -0
- data/test/unit/acts_methods_shoulda.rb +15 -0
- data/test/unit/common_methods_shoulda.rb +19 -2
- data/test/unit/parser_methods_shoulda.rb +5 -5
- data/test/unit/solr_instance.rb +0 -4
- data/test/unit/test_helper.rb +7 -0
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/acts_as_solr.rb
CHANGED
@@ -31,11 +31,14 @@ require File.dirname(__FILE__) + '/acts_as_solr/acts_methods'
|
|
31
31
|
require File.dirname(__FILE__) + '/acts_as_solr/common_methods'
|
32
32
|
require File.dirname(__FILE__) + '/acts_as_solr/parser_methods'
|
33
33
|
require File.dirname(__FILE__) + '/acts_as_solr/class_methods'
|
34
|
+
require File.dirname(__FILE__) + '/acts_as_solr/dynamic_attribute'
|
35
|
+
require File.dirname(__FILE__) + '/acts_as_solr/local'
|
34
36
|
require File.dirname(__FILE__) + '/acts_as_solr/instance_methods'
|
35
37
|
require File.dirname(__FILE__) + '/acts_as_solr/common_methods'
|
36
38
|
require File.dirname(__FILE__) + '/acts_as_solr/deprecation'
|
37
39
|
require File.dirname(__FILE__) + '/acts_as_solr/search_results'
|
38
40
|
require File.dirname(__FILE__) + '/acts_as_solr/lazy_document'
|
41
|
+
require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper'
|
39
42
|
module ActsAsSolr
|
40
43
|
|
41
44
|
class Post
|
@@ -62,4 +65,4 @@ module ActsAsSolr
|
|
62
65
|
end
|
63
66
|
|
64
67
|
# reopen ActiveRecord and include the acts_as_solr method
|
65
|
-
ActiveRecord::Base.extend ActsAsSolr::ActsMethods
|
68
|
+
ActiveRecord::Base.extend ActsAsSolr::ActsMethods
|
@@ -267,7 +267,7 @@ module ActsAsSolr #:nodoc:
|
|
267
267
|
}
|
268
268
|
self.solr_configuration = {
|
269
269
|
:type_field => "type_s",
|
270
|
-
:primary_key_field => "
|
270
|
+
:primary_key_field => "pk_s",
|
271
271
|
:default_boost => 1.0
|
272
272
|
}
|
273
273
|
|
@@ -349,15 +349,25 @@ module ActsAsSolr #:nodoc:
|
|
349
349
|
if configuration[:facets] && configuration[:facets].include?(field)
|
350
350
|
:facet
|
351
351
|
elsif column = columns_hash[field.to_s]
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
352
|
+
column_type = format_column_type(column.type)
|
353
|
+
|
354
|
+
case column_type
|
355
|
+
when :string then :text
|
356
|
+
when :datetime then :date
|
357
|
+
when :time then :date
|
358
|
+
else column_type
|
357
359
|
end
|
358
360
|
else
|
359
361
|
:text
|
360
362
|
end
|
361
363
|
end
|
364
|
+
|
365
|
+
def format_column_type(type)
|
366
|
+
if type.class.eql? Symbol
|
367
|
+
type
|
368
|
+
else
|
369
|
+
type.to_s.eql?("ObjectId") ? :string : type.to_s.downcase.to_sym
|
370
|
+
end
|
371
|
+
end
|
362
372
|
end
|
363
|
-
end
|
373
|
+
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'acts_as_solr/dynamic_attribute'
|
2
|
-
require 'acts_as_solr/local'
|
3
|
-
|
4
1
|
module ActsAsSolr #:nodoc:
|
5
2
|
|
6
3
|
module InstanceMethods
|
@@ -14,7 +11,7 @@ module ActsAsSolr #:nodoc:
|
|
14
11
|
def solr_save
|
15
12
|
return true if indexing_disabled?
|
16
13
|
if evaluate_condition(:if, self)
|
17
|
-
|
14
|
+
debug "solr_save: #{self.class.name} : #{record_id(self)}"
|
18
15
|
solr_add to_solr_doc
|
19
16
|
solr_commit if configuration[:auto_commit]
|
20
17
|
true
|
@@ -30,7 +27,7 @@ module ActsAsSolr #:nodoc:
|
|
30
27
|
# remove from index
|
31
28
|
def solr_destroy
|
32
29
|
return true if indexing_disabled?
|
33
|
-
|
30
|
+
debug "solr_destroy: #{self.class.name} : #{record_id(self)}"
|
34
31
|
solr_delete solr_id
|
35
32
|
solr_commit if configuration[:auto_commit]
|
36
33
|
true
|
@@ -38,7 +35,7 @@ module ActsAsSolr #:nodoc:
|
|
38
35
|
|
39
36
|
# convert instance to Solr document
|
40
37
|
def to_solr_doc
|
41
|
-
|
38
|
+
debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}"
|
42
39
|
doc = Solr::Document.new
|
43
40
|
doc.boost = validate_boost(configuration[:boost]) if configuration[:boost]
|
44
41
|
|
@@ -81,11 +78,16 @@ module ActsAsSolr #:nodoc:
|
|
81
78
|
add_tags(doc)
|
82
79
|
add_space(doc)
|
83
80
|
|
84
|
-
|
81
|
+
debug doc.to_xml
|
85
82
|
doc
|
86
83
|
end
|
87
84
|
|
88
85
|
private
|
86
|
+
|
87
|
+
def debug(text)
|
88
|
+
logger.debug text rescue nil
|
89
|
+
end
|
90
|
+
|
89
91
|
def add_space(doc)
|
90
92
|
if configuration[:spatial] and local
|
91
93
|
doc << Solr::Field.new("lat" => local.latitude)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActsAsSolr
|
2
|
+
module MongoMapper
|
3
|
+
def self.included(clazz)
|
4
|
+
clazz.extend ActsAsSolr::ActsMethods
|
5
|
+
clazz.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def columns_hash
|
10
|
+
keys
|
11
|
+
end
|
12
|
+
|
13
|
+
def primary_key
|
14
|
+
'id'
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(*args)
|
18
|
+
if args.first.instance_of? Array
|
19
|
+
ids = args.first.map { |id| Mongo::ObjectID.from_string(id) }
|
20
|
+
super :all, :conditions => {primary_key => ids}
|
21
|
+
else
|
22
|
+
super *args
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -104,7 +104,7 @@ module ActsAsSolr #:nodoc:
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def solr_type_condition
|
107
|
-
subclasses.inject("(#{solr_configuration[:type_field]}:#{self.name}") do |condition, subclass|
|
107
|
+
(subclasses || []).inject("(#{solr_configuration[:type_field]}:#{self.name}") do |condition, subclass|
|
108
108
|
condition << " OR #{solr_configuration[:type_field]}:#{subclass.name}"
|
109
109
|
end << ')'
|
110
110
|
end
|
@@ -148,12 +148,11 @@ module ActsAsSolr #:nodoc:
|
|
148
148
|
result = if configuration[:lazy] && configuration[:format] != :ids
|
149
149
|
ids.collect {|id| ActsAsSolr::LazyDocument.new(id, self)}
|
150
150
|
elsif configuration[:format] == :objects
|
151
|
-
|
152
|
-
find_options = {:conditions => conditions}
|
151
|
+
find_options = {}
|
153
152
|
find_options[:include] = options[:include] if options[:include]
|
154
153
|
find_options[:select] = options[:select] if options[:select]
|
155
154
|
find_options[:joins] = options[:joins] if options[:joins]
|
156
|
-
result = reorder(self.find(
|
155
|
+
result = reorder(self.find(ids, find_options), ids)
|
157
156
|
else
|
158
157
|
ids
|
159
158
|
end
|
@@ -166,7 +165,7 @@ module ActsAsSolr #:nodoc:
|
|
166
165
|
ordered_things = Array.new(things.size)
|
167
166
|
raise "Out of sync! Found #{ids.size} items in index, but only #{things.size} were found in database!" unless things.size == ids.size
|
168
167
|
things.each do |thing|
|
169
|
-
position = ids.index(thing.id)
|
168
|
+
position = ids.index(thing.id.to_s)
|
170
169
|
ordered_things[position] = thing
|
171
170
|
end
|
172
171
|
ordered_things
|
data/test/db/test.db
CHANGED
Binary file
|
@@ -4,6 +4,8 @@ require "#{File.dirname(File.expand_path(__FILE__))}/../test_helper"
|
|
4
4
|
class ActsAsSolrTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
fixtures :books, :movies, :electronics, :postings, :authors, :advertises
|
7
|
+
|
8
|
+
Document.destroy_all
|
7
9
|
|
8
10
|
DynamicAttribute.delete_all
|
9
11
|
Advertise.first.dynamic_attributes.create! :name => 'Description', :value => 'A very cool bike'
|
@@ -118,7 +120,7 @@ class ActsAsSolrTest < Test::Unit::TestCase
|
|
118
120
|
'author:peter AND ruby'].each do |term|
|
119
121
|
records = Book.find_id_by_solr term
|
120
122
|
assert_equal 1, records.docs.size
|
121
|
-
assert_equal [2], records.docs
|
123
|
+
assert_equal ['2'], records.docs
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
@@ -130,7 +132,7 @@ class ActsAsSolrTest < Test::Unit::TestCase
|
|
130
132
|
'author:clancy AND splinter'].each do |term|
|
131
133
|
records = Book.find_id_by_solr term
|
132
134
|
assert_equal 1, records.docs.size
|
133
|
-
assert_equal [1], records.docs
|
135
|
+
assert_equal ['1'], records.docs
|
134
136
|
end
|
135
137
|
end
|
136
138
|
|
@@ -142,7 +144,7 @@ class ActsAsSolrTest < Test::Unit::TestCase
|
|
142
144
|
'dummy OR cell'].each do |term|
|
143
145
|
records = Book.find_id_by_solr term
|
144
146
|
assert_equal 2, records.docs.size
|
145
|
-
assert_equal [1,2], records.docs
|
147
|
+
assert_equal ['1','2'], records.docs
|
146
148
|
end
|
147
149
|
end
|
148
150
|
|
@@ -460,4 +462,8 @@ class ActsAsSolrTest < Test::Unit::TestCase
|
|
460
462
|
assert_equal expected, records.highlights.values.first
|
461
463
|
end
|
462
464
|
|
465
|
+
def test_mongo_mappers_documents_are_found
|
466
|
+
Document.new(:name => "mapper").save
|
467
|
+
assert_equal "mapper", Document.search("mapper").docs.first.name
|
468
|
+
end
|
463
469
|
end
|
data/test/test_helper.rb
CHANGED
@@ -10,6 +10,10 @@ begin
|
|
10
10
|
rescue
|
11
11
|
end
|
12
12
|
|
13
|
+
require 'mongo_mapper'
|
14
|
+
|
15
|
+
MongoMapper.database = "acts_as_solr_reloaded-test"
|
16
|
+
|
13
17
|
RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT
|
14
18
|
RAILS_ENV = 'test' unless defined? RAILS_ENV
|
15
19
|
ENV["RAILS_ENV"] = "test"
|
@@ -47,6 +47,13 @@ class ActsMethodsTest < Test::Unit::TestCase
|
|
47
47
|
|
48
48
|
class NotTaggable < Abstract
|
49
49
|
end
|
50
|
+
|
51
|
+
class Mapper
|
52
|
+
include MongoMapper::Document
|
53
|
+
include ActsAsSolr::MongoMapper
|
54
|
+
key :value1, String
|
55
|
+
acts_as_solr
|
56
|
+
end
|
50
57
|
|
51
58
|
should "define the model as taggable if taggable is true" do
|
52
59
|
assert Taggable.taggable?
|
@@ -55,6 +62,14 @@ class ActsMethodsTest < Test::Unit::TestCase
|
|
55
62
|
should "not define the model as taggable if taggable is not true" do
|
56
63
|
assert !NotTaggable.taggable?
|
57
64
|
end
|
65
|
+
|
66
|
+
should "define the type of a MongoMapper document id as text" do
|
67
|
+
assert_equal :text, Mapper.configuration[:solr_fields][:_id][:type]
|
68
|
+
end
|
69
|
+
|
70
|
+
should "recognize the type String of a MongoMapper key as text" do
|
71
|
+
assert_equal :text, Mapper.configuration[:solr_fields][:value1][:type]
|
72
|
+
end
|
58
73
|
|
59
74
|
context "when getting field values" do
|
60
75
|
setup do
|
@@ -3,6 +3,16 @@ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
|
3
3
|
class CommonMethodsTest < Test::Unit::TestCase
|
4
4
|
include ActsAsSolr::CommonMethods
|
5
5
|
|
6
|
+
class Mongo
|
7
|
+
include MongoMapper::Document
|
8
|
+
include ActsAsSolr::MongoMapper
|
9
|
+
acts_as_solr
|
10
|
+
|
11
|
+
def id
|
12
|
+
'4b5e0119f3a4b02902000001'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
class << self
|
7
17
|
def primary_key
|
8
18
|
"id"
|
@@ -104,8 +114,15 @@ class CommonMethodsTest < Test::Unit::TestCase
|
|
104
114
|
end
|
105
115
|
|
106
116
|
context "when determining the record id" do
|
107
|
-
|
108
|
-
|
117
|
+
context "on ActiveRecord" do
|
118
|
+
should "return the primary key value" do
|
119
|
+
assert_equal 10, record_id(self)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
context "on MongoMapper" do
|
123
|
+
should "return the id value" do
|
124
|
+
assert_equal '4b5e0119f3a4b02902000001', record_id(Mongo.new)
|
125
|
+
end
|
109
126
|
end
|
110
127
|
end
|
111
128
|
end
|
@@ -39,7 +39,7 @@ class ParserMethodsTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
should "query with the record ids" do
|
42
|
-
@parser.expects(:find).with(
|
42
|
+
@parser.expects(:find).with([1, 2], {}).returns [1, 2]
|
43
43
|
@parser.parse_results(@results)
|
44
44
|
end
|
45
45
|
|
@@ -49,7 +49,7 @@ class ParserMethodsTest < Test::Unit::TestCase
|
|
49
49
|
end
|
50
50
|
|
51
51
|
should "add :include if :include was specified" do
|
52
|
-
@parser.expects(:find).with(
|
52
|
+
@parser.expects(:find).with([1, 2], :include => [:author]).returns [1, 2]
|
53
53
|
@parser.parse_results(@results, :include => [:author])
|
54
54
|
end
|
55
55
|
end
|
@@ -140,7 +140,7 @@ class ParserMethodsTest < Test::Unit::TestCase
|
|
140
140
|
thing3 = stub(:things3)
|
141
141
|
thing3.stubs(:id).returns 3
|
142
142
|
things = [thing1, thing2, thing3]
|
143
|
-
reordered = @parser.reorder(things, [1, 3, 5])
|
143
|
+
reordered = @parser.reorder(things, ['1', '3', '5'])
|
144
144
|
assert_equal [1, 3, 5], reordered.collect{|thing| thing.id}
|
145
145
|
end
|
146
146
|
end
|
@@ -162,7 +162,7 @@ class ParserMethodsTest < Test::Unit::TestCase
|
|
162
162
|
end
|
163
163
|
|
164
164
|
should "set the relevancy of the specified fields and non-filtered terms" do
|
165
|
-
expected = "(aeroplane brasil continent_t:south OR
|
165
|
+
expected = "(aeroplane brasil continent_t:south OR tag_t:(aeroplane brasil)^5 OR description_t:(aeroplane brasil)^3)"
|
166
166
|
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
167
167
|
request.to_hash[:q].starts_with? expected
|
168
168
|
}
|
@@ -178,7 +178,7 @@ class ParserMethodsTest < Test::Unit::TestCase
|
|
178
178
|
end
|
179
179
|
|
180
180
|
should "set the relevance with simple queries" do
|
181
|
-
expected = "(car OR
|
181
|
+
expected = "(car OR tag_t:(car)^5 OR description_t:(car)^3)"
|
182
182
|
ActsAsSolr::Post.expects(:execute).with {|request, core|
|
183
183
|
request.to_hash[:q].starts_with? expected
|
184
184
|
}
|
data/test/unit/solr_instance.rb
CHANGED
data/test/unit/test_helper.rb
CHANGED
@@ -12,6 +12,7 @@ require File.expand_path("#{dir}/solr_instance")
|
|
12
12
|
require File.expand_path("#{dir}/parser_instance")
|
13
13
|
require 'erb'
|
14
14
|
require 'ostruct'
|
15
|
+
require 'mongo_mapper'
|
15
16
|
|
16
17
|
if RUBY_VERSION =~ /^1\.9/
|
17
18
|
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."
|
@@ -22,3 +23,9 @@ end
|
|
22
23
|
require 'mocha'
|
23
24
|
gem 'thoughtbot-shoulda'
|
24
25
|
require 'shoulda'
|
26
|
+
|
27
|
+
class Rails
|
28
|
+
def self.logger
|
29
|
+
Logger.new(StringIO.new)
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_solr_reloaded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Carrion
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-26 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/acts_as_solr/instance_methods.rb
|
46
46
|
- lib/acts_as_solr/lazy_document.rb
|
47
47
|
- lib/acts_as_solr/local.rb
|
48
|
+
- lib/acts_as_solr/mongo_mapper.rb
|
48
49
|
- lib/acts_as_solr/parser_methods.rb
|
49
50
|
- lib/acts_as_solr/search_results.rb
|
50
51
|
- lib/acts_as_solr/solr_fixtures.rb
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- test/models/author.rb
|
204
205
|
- test/models/book.rb
|
205
206
|
- test/models/category.rb
|
207
|
+
- test/models/document.rb
|
206
208
|
- test/models/dynamic_attribute.rb
|
207
209
|
- test/models/electronic.rb
|
208
210
|
- test/models/gadget.rb
|
@@ -271,6 +273,7 @@ test_files:
|
|
271
273
|
- test/models/author.rb
|
272
274
|
- test/models/book.rb
|
273
275
|
- test/models/category.rb
|
276
|
+
- test/models/document.rb
|
274
277
|
- test/models/dynamic_attribute.rb
|
275
278
|
- test/models/electronic.rb
|
276
279
|
- test/models/gadget.rb
|