rsolr 0.12.0 → 1.0.3
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/README.rdoc +147 -51
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/lib/rsolr/char.rb +21 -0
- data/lib/rsolr/client.rb +216 -70
- data/lib/rsolr/connection.rb +78 -9
- data/lib/rsolr/error.rb +117 -0
- data/lib/rsolr/response.rb +51 -0
- data/lib/rsolr/uri.rb +58 -0
- data/lib/rsolr/xml.rb +165 -0
- data/lib/rsolr-direct.rb +111 -0
- data/lib/rsolr.rb +11 -27
- data/spec/api/char_spec.rb +18 -0
- data/spec/api/client_spec.rb +216 -0
- data/spec/api/connection_spec.rb +15 -0
- data/spec/api/error_spec.rb +56 -0
- data/spec/api/pagination_spec.rb +30 -0
- data/spec/api/rsolr_spec.rb +19 -0
- data/spec/api/uri_spec.rb +70 -0
- data/spec/api/xml_spec.rb +121 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/rdoc.rake +11 -0
- data/tasks/spec.rake +39 -0
- metadata +144 -25
- data/CHANGES.txt +0 -282
- data/lib/rsolr/connection/net_http.rb +0 -48
- data/lib/rsolr/connection/requestable.rb +0 -43
- data/lib/rsolr/connection/utils.rb +0 -73
- data/lib/rsolr/message/document.rb +0 -48
- data/lib/rsolr/message/field.rb +0 -20
- data/lib/rsolr/message/generator.rb +0 -89
- data/lib/rsolr/message.rb +0 -8
- data/rsolr.gemspec +0 -32
@@ -1,48 +0,0 @@
|
|
1
|
-
# A class that represents a "doc" xml element for a solr update
|
2
|
-
class RSolr::Message::Document
|
3
|
-
|
4
|
-
# "attrs" is a hash for setting the "doc" xml attributes
|
5
|
-
# "fields" is an array of Field objects
|
6
|
-
attr_accessor :attrs, :fields
|
7
|
-
|
8
|
-
# "doc_hash" must be a Hash/Mash object
|
9
|
-
# If a value in the "doc_hash" is an array,
|
10
|
-
# a field object is created for each value...
|
11
|
-
def initialize(doc_hash = {})
|
12
|
-
@fields = []
|
13
|
-
doc_hash.each_pair do |field,values|
|
14
|
-
# create a new field for each value (multi-valued)
|
15
|
-
# put non-array values into an array
|
16
|
-
values = [values] unless values.is_a?(Array)
|
17
|
-
values.each do |v|
|
18
|
-
next if v.to_s.empty?
|
19
|
-
@fields << RSolr::Message::Field.new({:name=>field}, v.to_s)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
@attrs={}
|
23
|
-
end
|
24
|
-
|
25
|
-
# returns an array of fields that match the "name" arg
|
26
|
-
def fields_by_name(name)
|
27
|
-
@fields.select{|f|f.name==name}
|
28
|
-
end
|
29
|
-
|
30
|
-
# returns the *first* field that matches the "name" arg
|
31
|
-
def field_by_name(name)
|
32
|
-
@fields.detect{|f|f.name==name}
|
33
|
-
end
|
34
|
-
|
35
|
-
#
|
36
|
-
# Add a field value to the document. Options map directly to
|
37
|
-
# XML attributes in the Solr <field> node.
|
38
|
-
# See http://wiki.apache.org/solr/UpdateXmlMessages#head-8315b8028923d028950ff750a57ee22cbf7977c6
|
39
|
-
#
|
40
|
-
# === Example:
|
41
|
-
#
|
42
|
-
# document.add_field('title', 'A Title', :boost => 2.0)
|
43
|
-
#
|
44
|
-
def add_field(name, value, options = {})
|
45
|
-
@fields << RSolr::Message::Field.new(options.merge({:name=>name}), value)
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
data/lib/rsolr/message/field.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# A class that represents a "doc"/"field" xml element for a solr update
|
2
|
-
class RSolr::Message::Field
|
3
|
-
|
4
|
-
# "attrs" is a hash for setting the "doc" xml attributes
|
5
|
-
# "value" is the text value for the node
|
6
|
-
attr_accessor :attrs, :value
|
7
|
-
|
8
|
-
# "attrs" must be a hash
|
9
|
-
# "value" should be something that responds to #_to_s
|
10
|
-
def initialize(attrs, value)
|
11
|
-
@attrs = attrs
|
12
|
-
@value = value
|
13
|
-
end
|
14
|
-
|
15
|
-
# the value of the "name" attribute
|
16
|
-
def name
|
17
|
-
@attrs[:name]
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
class RSolr::Message::Generator
|
2
|
-
|
3
|
-
def build &block
|
4
|
-
require 'builder'
|
5
|
-
b = ::Builder::XmlMarkup.new(:indent=>0, :margin=>0, :encoding => 'UTF-8')
|
6
|
-
b.instruct!
|
7
|
-
block_given? ? yield(b) : b
|
8
|
-
end
|
9
|
-
|
10
|
-
# generates "add" xml for updating solr
|
11
|
-
# "data" can be a hash or an array of hashes.
|
12
|
-
# - each hash should be a simple key=>value pair representing a solr doc.
|
13
|
-
# If a value is an array, multiple fields will be created.
|
14
|
-
#
|
15
|
-
# "add_attrs" can be a hash for setting the add xml element attributes.
|
16
|
-
#
|
17
|
-
# This method can also accept a block.
|
18
|
-
# The value yielded to the block is a Message::Document; for each solr doc in "data".
|
19
|
-
# You can set xml element attributes for each "doc" element or individual "field" elements.
|
20
|
-
#
|
21
|
-
# For example:
|
22
|
-
#
|
23
|
-
# solr.add({:id=>1, :nickname=>'Tim'}, {:boost=>5.0, :commitWithin=>1.0}) do |doc_msg|
|
24
|
-
# doc_msg.attrs[:boost] = 10.00 # boost the document
|
25
|
-
# nickname = doc_msg.field_by_name(:nickname)
|
26
|
-
# nickname.attrs[:boost] = 20 if nickname.value=='Tim' # boost a field
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# would result in an add element having the attributes boost="10.0"
|
30
|
-
# and a commitWithin="1.0".
|
31
|
-
# Each doc element would have a boost="10.0".
|
32
|
-
# The "nickname" field would have a boost="20.0"
|
33
|
-
# if the doc had a "nickname" field with the value of "Tim".
|
34
|
-
#
|
35
|
-
def add data, add_attrs={}, &block
|
36
|
-
data = [data] unless data.is_a?(Array)
|
37
|
-
build do |xml|
|
38
|
-
xml.add(add_attrs) do |add_node|
|
39
|
-
data.each do |doc|
|
40
|
-
doc = RSolr::Message::Document.new(doc) if doc.respond_to?(:each_pair)
|
41
|
-
yield doc if block_given?
|
42
|
-
add_node.doc(doc.attrs) do |doc_node|
|
43
|
-
doc.fields.each do |field_obj|
|
44
|
-
doc_node.field field_obj.value, field_obj.attrs
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# generates a <commit/> message
|
53
|
-
def commit(opts={})
|
54
|
-
build {|xml| xml.commit opts}
|
55
|
-
end
|
56
|
-
|
57
|
-
# generates a <optimize/> message
|
58
|
-
def optimize(opts={})
|
59
|
-
build {|xml| xml.optimize opts}
|
60
|
-
end
|
61
|
-
|
62
|
-
# generates a <rollback/> message
|
63
|
-
def rollback opts={}
|
64
|
-
build {|xml| xml.rollback opts}
|
65
|
-
end
|
66
|
-
|
67
|
-
# generates a <delete><id>ID</id></delete> message
|
68
|
-
# "ids" can be a single value or array of values
|
69
|
-
def delete_by_id(ids)
|
70
|
-
ids = [ids] unless ids.is_a?(Array)
|
71
|
-
build do |xml|
|
72
|
-
xml.delete do |delete_node|
|
73
|
-
ids.each { |id| delete_node.id(id) }
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# generates a <delete><query>ID</query></delete> message
|
79
|
-
# "queries" can be a single value or an array of values
|
80
|
-
def delete_by_query(queries)
|
81
|
-
queries = [queries] unless queries.is_a?(Array)
|
82
|
-
build do |xml|
|
83
|
-
xml.delete do |delete_node|
|
84
|
-
queries.each { |query| delete_node.query query }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/lib/rsolr/message.rb
DELETED
data/rsolr.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
|
3
|
-
s.name = "rsolr"
|
4
|
-
s.version = "0.12.0"
|
5
|
-
s.date = "2010-02-03"
|
6
|
-
s.summary = "A Ruby client for Apache Solr"
|
7
|
-
s.email = "goodieboy@gmail.com"
|
8
|
-
s.homepage = "http://github.com/mwmitchell/rsolr"
|
9
|
-
s.description = "RSolr is a Ruby gem for working with Apache Solr!"
|
10
|
-
s.has_rdoc = true
|
11
|
-
s.authors = ["Matt Mitchell"]
|
12
|
-
|
13
|
-
s.files = [
|
14
|
-
"CHANGES.txt",
|
15
|
-
"lib/rsolr/client.rb",
|
16
|
-
"lib/rsolr/connection/net_http.rb",
|
17
|
-
"lib/rsolr/connection/requestable.rb",
|
18
|
-
"lib/rsolr/connection/utils.rb",
|
19
|
-
"lib/rsolr/connection.rb",
|
20
|
-
"lib/rsolr/message/document.rb",
|
21
|
-
"lib/rsolr/message/field.rb",
|
22
|
-
"lib/rsolr/message/generator.rb",
|
23
|
-
"lib/rsolr/message.rb",
|
24
|
-
"lib/rsolr.rb",
|
25
|
-
"LICENSE",
|
26
|
-
"README.rdoc",
|
27
|
-
"rsolr.gemspec"
|
28
|
-
]
|
29
|
-
|
30
|
-
#s.rdoc_options = ["--main", "README.rdoc"]
|
31
|
-
s.extra_rdoc_files = %w(LICENSE README.rdoc CHANGES.txt)
|
32
|
-
end
|