solr_mapper 0.1.3 → 0.1.4

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 CHANGED
@@ -1,5 +1,4 @@
1
1
  LICENSE.txt
2
- Manifest
3
2
  README.rdoc
4
3
  Rakefile
5
4
  lib/solr_mapper.rb
@@ -7,7 +6,6 @@ lib/solr_mapper/calculations.rb
7
6
  lib/solr_mapper/locators.rb
8
7
  lib/solr_mapper/relations.rb
9
8
  lib/solr_mapper/solr_document.rb
10
- solr_mapper.gemspec
11
9
  spec/base.rb
12
10
  spec/calculations_spec.rb
13
11
  spec/locators_spec.rb
@@ -19,3 +17,4 @@ spec/solr/stuff/config/schema.xml
19
17
  spec/solr/thing/config/schema.xml
20
18
  spec/solr/widget/conf/schema.xml
21
19
  spec/url_spec.rb
20
+ Manifest
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.3') do |p|
19
+ Echoe.new('solr_mapper', '0.1.4') 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"
@@ -25,10 +25,12 @@ module SolrMapper
25
25
  attr_accessor :per_page
26
26
  attr_accessor :solr_fields
27
27
 
28
+ # send a read REST command to Solr
28
29
  def execute_read(opts)
29
30
  eval(RestClient.get(build_url('select', opts.merge(:wt => 'ruby'))))
30
31
  end
31
32
 
33
+ # send a write REST command to SOlr
32
34
  def execute_write(data, opts = nil)
33
35
  send_update(data, opts)
34
36
 
@@ -47,6 +49,7 @@ module SolrMapper
47
49
  URI::escape("#{base_url}/#{path}#{qs}")
48
50
  end
49
51
 
52
+ # create a querystring from a hash
50
53
  def build_qs(opts)
51
54
  uri = ''
52
55
 
@@ -66,11 +69,13 @@ module SolrMapper
66
69
  query(values, opts)
67
70
  end
68
71
 
72
+ # main interface by which consumers search solr via SolrMapper
69
73
  def query(values, opts = {})
70
74
  results, _ = query_counted(values, opts)
71
75
  results
72
76
  end
73
77
 
78
+ # execute solr query and return the count as well as the results
74
79
  def query_counted(values, opts = {})
75
80
  if values.kind_of?(Hash)
76
81
  search_string = ''
@@ -88,6 +93,7 @@ module SolrMapper
88
93
  return map(response), response['response']['numFound']
89
94
  end
90
95
 
96
+ # look up an object by primary key
91
97
  def find(id)
92
98
  result = query(:id => id)
93
99
  return result[0] if result.count > 0
@@ -114,29 +120,32 @@ module SolrMapper
114
120
  end
115
121
 
116
122
  protected
123
+ # map values returned from Solr into ruby objects
117
124
  def map(docs)
118
125
  objs = []
119
126
 
120
127
  docs['response']['docs'].each do |doc|
121
128
  obj = self.new
129
+ obj.send(:before_load) if obj.respond_to?(:before_load)
122
130
 
123
131
  doc.each_pair do |k, v|
124
132
  k = '_id' if k.to_s == 'id'
125
133
 
126
- unless obj.class.method_defined?(k)
127
- class_eval { attr_accessor k }
128
- solr_fields << k.to_s unless solr_fields.include?(k.to_s)
129
- end
130
-
131
- obj.instance_variable_set("@#{k}", v)
134
+ class_eval { attr_accessor k } unless obj.respond_to?("#{k}=")
135
+ self.solr_fields << k unless self.solr_fields.include?(k)
136
+
137
+ obj.send("#{k}=", v)
132
138
  end
133
139
 
140
+ obj.send(:after_load) if obj.respond_to?(:after_load)
141
+
134
142
  objs << obj
135
143
  end
136
144
 
137
145
  objs
138
146
  end
139
147
 
148
+
140
149
  def send_update(data, opts = nil)
141
150
  solr_resource = RestClient::Resource.new(build_url('update', opts))
142
151
  solr_resource.post(data, {:content_type => 'text/xml'})
@@ -154,9 +163,14 @@ module SolrMapper
154
163
  end
155
164
 
156
165
  def save()
166
+ send(:before_save) if respond_to?(:before_save)
167
+
157
168
  self.class.execute_write(to_solr_xml, {:overwrite => true})
169
+
170
+ send(:after_save) if respond_to?(:after_save)
158
171
  end
159
172
 
173
+ # remove an object from the index
160
174
  def destroy
161
175
  # make an xml delete message that Solr will be happy with
162
176
  delete_message = ''
@@ -169,6 +183,7 @@ module SolrMapper
169
183
  self.class.execute_write(delete_message)
170
184
  end
171
185
 
186
+ # convert a ruby object to xml compliant with a Solr update REST command
172
187
  def to_solr_xml
173
188
  output = ''
174
189
  builder = Builder::XmlMarkup.new(:target => output, :indent => 2)
@@ -214,6 +229,7 @@ module SolrMapper
214
229
  save()
215
230
  end
216
231
 
232
+ # handle rails building a url from us
217
233
  def to_param
218
234
  instance_variable_get('@_id').to_s
219
235
  end
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.3"
5
+ s.version = "0.1.4"
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-10-26}
9
+ s.date = %q{2010-10-27}
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", "Manifest", "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", "solr_mapper.gemspec", "spec/base.rb", "spec/calculations_spec.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"]
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/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"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chris Umbel
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-26 00:00:00 +00:00
17
+ date: 2010-10-27 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -85,7 +85,6 @@ extra_rdoc_files:
85
85
  - lib/solr_mapper/solr_document.rb
86
86
  files:
87
87
  - LICENSE.txt
88
- - Manifest
89
88
  - README.rdoc
90
89
  - Rakefile
91
90
  - lib/solr_mapper.rb
@@ -93,7 +92,6 @@ files:
93
92
  - lib/solr_mapper/locators.rb
94
93
  - lib/solr_mapper/relations.rb
95
94
  - lib/solr_mapper/solr_document.rb
96
- - solr_mapper.gemspec
97
95
  - spec/base.rb
98
96
  - spec/calculations_spec.rb
99
97
  - spec/locators_spec.rb
@@ -105,6 +103,8 @@ files:
105
103
  - spec/solr/thing/config/schema.xml
106
104
  - spec/solr/widget/conf/schema.xml
107
105
  - spec/url_spec.rb
106
+ - Manifest
107
+ - solr_mapper.gemspec
108
108
  has_rdoc: true
109
109
  homepage: http://github.com/skunkworx/solr_mapper
110
110
  licenses: []