solr_mapper 0.1.8 → 0.1.9
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/Manifest +1 -0
- data/README.rdoc +14 -0
- data/Rakefile +1 -1
- data/lib/solr_mapper/relations.rb +8 -0
- data/lib/solr_mapper/solr_document.rb +15 -2
- data/solr_mapper.gemspec +3 -3
- data/spec/generation.rb +49 -0
- metadata +6 -13
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -44,6 +44,20 @@ gem install solr_mapper
|
|
44
44
|
has_one :widget
|
45
45
|
end
|
46
46
|
|
47
|
+
=== Auto Generated IDs
|
48
|
+
|
49
|
+
as of 0.1.9 you can cause a document to create a UUID id
|
50
|
+
for new objects with:
|
51
|
+
|
52
|
+
class Stuff
|
53
|
+
include SolrDocument
|
54
|
+
|
55
|
+
# tells solr_mapper to generate the id
|
56
|
+
auto_generate_id
|
57
|
+
|
58
|
+
bind_service_url 'http://localhost:8080/solr/stuff'
|
59
|
+
end
|
60
|
+
|
47
61
|
=== Reading
|
48
62
|
|
49
63
|
thing = Thing.find(1)
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ require 'rubygems'
|
|
16
16
|
require 'rake'
|
17
17
|
require 'echoe'
|
18
18
|
|
19
|
-
Echoe.new('solr_mapper', '0.1.
|
19
|
+
Echoe.new('solr_mapper', '0.1.9') do |p|
|
20
20
|
p.description = "Object Document Mapper for the Apache Foundation's Solr search platform"
|
21
21
|
p.url = "http://github.com/skunkworx/solr_mapper"
|
22
22
|
p.author = "Chris Umbel"
|
@@ -17,6 +17,7 @@ module SolrMapper
|
|
17
17
|
module ClassMethods
|
18
18
|
attr_accessor :has_many_relationships
|
19
19
|
|
20
|
+
# handle a has one relationship. this document contains a foreign key to a doc in another index
|
20
21
|
def has_one(target, opts = {})
|
21
22
|
class_name, field_name, variable_name, id_field = determine_names(target, opts)
|
22
23
|
|
@@ -38,6 +39,7 @@ module SolrMapper
|
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
42
|
+
# handle a has one relationship. this document contains a foreign key to another index's documents
|
41
43
|
def has_many(target, opts = {})
|
42
44
|
class_name, field_name, variable_name, id_field = determine_names(target, opts)
|
43
45
|
@@facet_field_name = field_name
|
@@ -147,14 +149,17 @@ module SolrMapper
|
|
147
149
|
end
|
148
150
|
end
|
149
151
|
|
152
|
+
# handle a belongs to relation. target index contains document with foreign keys to this document
|
150
153
|
def belongs_to(target_name, opts = {})
|
151
154
|
target_id_field_name = foreign_key(self.name)
|
152
155
|
|
153
156
|
class_eval do
|
157
|
+
# create getter for owner object
|
154
158
|
define_method target_name do
|
155
159
|
owner = instance_variable_get("@#{target_name}")
|
156
160
|
|
157
161
|
unless owner
|
162
|
+
# owner object hasn't been lazy loaded. do so now.
|
158
163
|
owner = Object::const_get(classify(target_name)).query(target_id_field_name => instance_variable_get("@_id"))[0]
|
159
164
|
instance_variable_set("@#{target_name}", owner)
|
160
165
|
end
|
@@ -162,6 +167,7 @@ module SolrMapper
|
|
162
167
|
owner
|
163
168
|
end
|
164
169
|
|
170
|
+
# create setter for owner object
|
165
171
|
define_method "#{target_name}=" do |val|
|
166
172
|
instance_variable_set("@#{target_name}", val)
|
167
173
|
val.instance_variable_set("@#{target_id_field_name}", instance_variable_get("@_id"))
|
@@ -172,6 +178,7 @@ module SolrMapper
|
|
172
178
|
|
173
179
|
protected
|
174
180
|
|
181
|
+
# figure out the names of properties and classes involved in the relation
|
175
182
|
def determine_names(target, opts = {})
|
176
183
|
class_name = opts[:class_name]
|
177
184
|
class_name ||= classify(target)
|
@@ -184,6 +191,7 @@ module SolrMapper
|
|
184
191
|
end
|
185
192
|
end
|
186
193
|
|
194
|
+
# when the owner collection is modified this will be called sync the relation up
|
187
195
|
def refresh_relation(field_name)
|
188
196
|
ids = instance_variable_get("@#{self.class.has_many_relationships[field_name]}")
|
189
197
|
ids.clear
|
@@ -38,6 +38,14 @@ module SolrMapper
|
|
38
38
|
@base_url
|
39
39
|
end
|
40
40
|
|
41
|
+
def auto_generate_id
|
42
|
+
@auto_geneerate_id = true
|
43
|
+
end
|
44
|
+
|
45
|
+
def auto_generate_id?
|
46
|
+
@auto_geneerate_id
|
47
|
+
end
|
48
|
+
|
41
49
|
# send a read REST command to Solr
|
42
50
|
def execute_read(opts)
|
43
51
|
url = build_url('select', opts.merge(:wt => 'ruby'))
|
@@ -47,7 +55,7 @@ module SolrMapper
|
|
47
55
|
# send a write REST command to Solr
|
48
56
|
def execute_write(data, opts = nil)
|
49
57
|
send_update(data, opts)
|
50
|
-
|
58
|
+
|
51
59
|
# make an xml commit message Solr will be happy with
|
52
60
|
commit_message = ''
|
53
61
|
builder = Builder::XmlMarkup.new(:target => commit_message, :indent => 2)
|
@@ -180,6 +188,7 @@ module SolrMapper
|
|
180
188
|
|
181
189
|
attr_accessor :_id
|
182
190
|
|
191
|
+
# the property doesn't exist for this document. add it now.
|
183
192
|
def method_missing(m, *args, &block)
|
184
193
|
method_name = m.to_s
|
185
194
|
assignment = method_name.match(/\=$/)
|
@@ -190,9 +199,13 @@ module SolrMapper
|
|
190
199
|
|
191
200
|
def save()
|
192
201
|
send(:before_save) if respond_to?(:before_save)
|
202
|
+
|
203
|
+
if not @_id and self.class.auto_generate_id?
|
204
|
+
@_id = UUID.new().generate()
|
205
|
+
self.class.solr_fields << '_id' unless self.class.solr_fields.include?('_id')
|
206
|
+
end
|
193
207
|
|
194
208
|
self.class.execute_write(to_solr_xml, {:overwrite => true})
|
195
|
-
|
196
209
|
send(:after_save) if respond_to?(:after_save)
|
197
210
|
end
|
198
211
|
|
data/solr_mapper.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{solr_mapper}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chris Umbel"]
|
9
|
-
s.date = %q{2010-12-
|
9
|
+
s.date = %q{2010-12-28}
|
10
10
|
s.description = %q{Object Document Mapper for the Apache Foundation's Solr search platform}
|
11
11
|
s.email = %q{chrisu@dvdempire.com}
|
12
12
|
s.extra_rdoc_files = ["LICENSE.txt", "README.rdoc", "lib/solr_mapper.rb", "lib/solr_mapper/calculations.rb", "lib/solr_mapper/locators.rb", "lib/solr_mapper/relations.rb", "lib/solr_mapper/solr_document.rb"]
|
13
|
-
s.files = ["LICENSE.txt", "
|
13
|
+
s.files = ["LICENSE.txt", "README.rdoc", "Rakefile", "lib/solr_mapper.rb", "lib/solr_mapper/calculations.rb", "lib/solr_mapper/locators.rb", "lib/solr_mapper/relations.rb", "lib/solr_mapper/solr_document.rb", "spec/base.rb", "spec/calculations_spec.rb", "spec/facets_spec.rb", "spec/generation.rb", "spec/locators_spec.rb", "spec/misc_spec.rb", "spec/paginated_spec.rb", "spec/query_spec.rb", "spec/relation_spec.rb", "spec/solr/stuff/config/schema.xml", "spec/solr/thing/config/schema.xml", "spec/solr/widget/conf/schema.xml", "spec/url_spec.rb", "Manifest", "solr_mapper.gemspec"]
|
14
14
|
s.homepage = %q{http://github.com/skunkworx/solr_mapper}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Solr_mapper", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
data/spec/generation.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Copyright 2010 The Skunkworx.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require File.dirname(__FILE__) + '/base'
|
16
|
+
|
17
|
+
include SolrMapper
|
18
|
+
|
19
|
+
describe SolrDocument do
|
20
|
+
before(:all) do
|
21
|
+
class Thing
|
22
|
+
auto_generate_id
|
23
|
+
end
|
24
|
+
|
25
|
+
url = Thing::base_url
|
26
|
+
resource = RestClient::Resource.new("#{url}/update")
|
27
|
+
resource.post("<delete><query>id:[* TO *]</query></delete>", {:content_type => 'text/xml'})
|
28
|
+
resource.post("<commit/>", {:content_type => 'text/xml'})
|
29
|
+
|
30
|
+
thing = Thing.new({:name => 'A', :content => 'sample content 1'})
|
31
|
+
thing.save
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have an auto generated id" do
|
35
|
+
thing = Thing.first()
|
36
|
+
thing._id.should_not be(nil)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "shouldn't let the id change after successive saves" do
|
40
|
+
thing = Thing.first()
|
41
|
+
old_id = thing._id
|
42
|
+
thing.save()
|
43
|
+
thing._id.should == old_id
|
44
|
+
end
|
45
|
+
|
46
|
+
after(:all) do
|
47
|
+
Thing.class_eval("@auto_generate_id = false")
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solr_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 11
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 9
|
9
|
+
version: 0.1.9
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Chris Umbel
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-28 00:00:00 +00:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -40,7 +38,6 @@ dependencies:
|
|
40
38
|
requirements:
|
41
39
|
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
41
|
segments:
|
45
42
|
- 0
|
46
43
|
version: "0"
|
@@ -54,7 +51,6 @@ dependencies:
|
|
54
51
|
requirements:
|
55
52
|
- - ">="
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
54
|
segments:
|
59
55
|
- 0
|
60
56
|
version: "0"
|
@@ -68,7 +64,6 @@ dependencies:
|
|
68
64
|
requirements:
|
69
65
|
- - ">="
|
70
66
|
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
67
|
segments:
|
73
68
|
- 0
|
74
69
|
version: "0"
|
@@ -82,7 +77,6 @@ dependencies:
|
|
82
77
|
requirements:
|
83
78
|
- - ">="
|
84
79
|
- !ruby/object:Gem::Version
|
85
|
-
hash: 3
|
86
80
|
segments:
|
87
81
|
- 2
|
88
82
|
- 0
|
@@ -105,7 +99,6 @@ extra_rdoc_files:
|
|
105
99
|
- lib/solr_mapper/solr_document.rb
|
106
100
|
files:
|
107
101
|
- LICENSE.txt
|
108
|
-
- Manifest
|
109
102
|
- README.rdoc
|
110
103
|
- Rakefile
|
111
104
|
- lib/solr_mapper.rb
|
@@ -113,10 +106,10 @@ files:
|
|
113
106
|
- lib/solr_mapper/locators.rb
|
114
107
|
- lib/solr_mapper/relations.rb
|
115
108
|
- lib/solr_mapper/solr_document.rb
|
116
|
-
- solr_mapper.gemspec
|
117
109
|
- spec/base.rb
|
118
110
|
- spec/calculations_spec.rb
|
119
111
|
- spec/facets_spec.rb
|
112
|
+
- spec/generation.rb
|
120
113
|
- spec/locators_spec.rb
|
121
114
|
- spec/misc_spec.rb
|
122
115
|
- spec/paginated_spec.rb
|
@@ -126,6 +119,8 @@ files:
|
|
126
119
|
- spec/solr/thing/config/schema.xml
|
127
120
|
- spec/solr/widget/conf/schema.xml
|
128
121
|
- spec/url_spec.rb
|
122
|
+
- Manifest
|
123
|
+
- solr_mapper.gemspec
|
129
124
|
has_rdoc: true
|
130
125
|
homepage: http://github.com/skunkworx/solr_mapper
|
131
126
|
licenses: []
|
@@ -145,7 +140,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
140
|
requirements:
|
146
141
|
- - ">="
|
147
142
|
- !ruby/object:Gem::Version
|
148
|
-
hash: 3
|
149
143
|
segments:
|
150
144
|
- 0
|
151
145
|
version: "0"
|
@@ -154,7 +148,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
148
|
requirements:
|
155
149
|
- - ">="
|
156
150
|
- !ruby/object:Gem::Version
|
157
|
-
hash: 11
|
158
151
|
segments:
|
159
152
|
- 1
|
160
153
|
- 2
|