rsolr 2.5.0 → 3.0.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/README.rdoc DELETED
@@ -1,227 +0,0 @@
1
- =RSolr
2
-
3
- A simple, extensible Ruby client for Apache Solr.
4
-
5
- ==Documentation
6
- The code docs http://www.rubydoc.info/gems/rsolr
7
-
8
- == Installation:
9
- gem install rsolr
10
-
11
- == Example:
12
- require 'rsolr'
13
-
14
- # Direct connection
15
- solr = RSolr.connect :url => 'http://solrserver.com'
16
-
17
- # Connecting over a proxy server
18
- solr = RSolr.connect :url => 'http://solrserver.com', :proxy=>'http://user:pass@proxy.example.com:8080'
19
-
20
- # Using an alternate Faraday adapter
21
- solr = RSolr.connect :url => 'http://solrserver.com', :adapter => :em_http
22
-
23
- # Using a custom Faraday connection
24
- conn = Faraday.new do |faraday|
25
- faraday.response :logger # log requests to STDOUT
26
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
27
- end
28
- solr = RSolr.connect conn, :url => 'http://solrserver.com'
29
-
30
- # send a request to /select
31
- response = solr.get 'select', :params => {:q => '*:*'}
32
-
33
- # send a request to /catalog
34
- response = solr.get 'catalog', :params => {:q => '*:*'}
35
-
36
- When the Solr +:wt+ is +:ruby+, then the response will be a Hash. This Hash is the same object returned by Solr, but evaluated as Ruby. If the +:wt+ is not +:ruby+, then the response will be a String.
37
-
38
- The response also exposes 2 attribute readers (for any +:wt+ value), +:request+ and +:response+. Both are Hash objects with symbolized keys.
39
-
40
- The +:request+ attribute contains the original request context. You can use this for debugging or logging. Some of the keys this object contains are +:uri+, +:query+, +:method+ etc..
41
-
42
- The +:response+ attribute contains the original response. This object contains the +:status+, +:body+ and +:headers+ keys.
43
-
44
- == Request formats
45
-
46
- By default, RSolr uses the Solr JSON command format for all requests.
47
-
48
- RSolr.connect :url => 'http://solrserver.com', update_format: :json # the default
49
- # or
50
- RSolr.connect :url => 'http://solrserver.com', update_format: :xml
51
-
52
- == Timeouts
53
- The read and connect timeout settings can be set when creating a new instance of RSolr, and will
54
- be passed on to underlying Faraday instance:
55
-
56
- solr = RSolr.connect(:timeout => 120, :open_timeout => 120)
57
-
58
- == Retry 503s
59
- A 503 is usually a temporary error which RSolr may retry if requested. You may specify the number of retry attempts with the +:retry_503+ option.
60
-
61
- Only requests which specify a Retry-After header will be retried, after waiting the indicated retry interval, otherwise RSolr will treat the request as a 500. You may specify a maximum Retry-After interval to wait with the +:retry_after_limit+ option (default: one second).
62
- solr = RSolr.connect(:retry_503 => 1, :retry_after_limit => 1)
63
-
64
- For additional control, consider using a custom Faraday connection (see above) using its `retry` middleware.
65
-
66
- == Querying
67
- Use the #get / #post method to send search requests to the /select handler:
68
- response = solr.get 'select', :params => {
69
- :q=>'washington',
70
- :start=>0,
71
- :rows=>10
72
- }
73
- response["response"]["docs"].each{|doc| puts doc["id"] }
74
-
75
- The +:params+ sent into the method are sent to Solr as-is, which is to say they are converted to Solr url style, but no special mapping is used.
76
- When an array is used, multiple parameters *with the same name* are generated for the Solr query. Example:
77
-
78
- solr.get 'select', :params => {:q=>'roses', :fq=>['red', 'violet']}
79
-
80
- The above statement generates this Solr query:
81
-
82
- select?q=roses&fq=red&fq=violet
83
-
84
- ===Pagination
85
- To paginate through a set of Solr documents, use the paginate method:
86
- solr.paginate 1, 10, "select", :params => {:q => "test"}
87
-
88
- The first argument is the current page, the second is how many documents to return for each page. In other words, "page" is the "start" Solr param and "per-page" is the "rows" Solr param.
89
-
90
- The paginate method returns WillPaginate ready "docs" objects, so for example in a Rails application, paginating is as simple as:
91
- <%= will_paginate @solr_response["response"]["docs"] %>
92
-
93
- ===Method Missing
94
- The +RSolr::Client+ class also uses +method_missing+ for setting the request handler/path:
95
-
96
- solr.paintings :params => {:q=>'roses', :fq=>['red', 'violet']}
97
-
98
- This is sent to Solr as:
99
- paintings?q=roses&fq=red&fq=violet
100
-
101
- This works with pagination as well:
102
-
103
- solr.paginate_paintings 1, 10, {:q=>'roses', :fq=>['red', 'violet']}
104
-
105
- ===Using POST for Search Queries
106
- There may be cases where the query string is too long for a GET request. RSolr solves this issue by converting hash objects into form-encoded strings:
107
- response = solr.music :data => {:q => "*:*"}
108
-
109
- The +:data+ hash is serialized as a form-encoded query string, and the correct content-type headers are sent along to Solr.
110
-
111
- ===Sending HEAD Requests
112
- There may be cases where you'd like to send a HEAD request to Solr:
113
- solr.head("admin/ping").response[:status] == 200
114
-
115
- ==Sending HTTP Headers
116
- Solr responds to the request headers listed here: http://wiki.apache.org/solr/SolrAndHTTPCaches
117
- To send header information to Solr using RSolr, just use the +:headers+ option:
118
- response = solr.head "admin/ping", :headers => {"Cache-Control" => "If-None-Match"}
119
-
120
- ===Building a Request
121
- +RSolr::Client+ provides a method for building a request context, which can be useful for debugging or logging etc.:
122
- request_context = solr.build_request "select", :data => {:q => "*:*"}, :method => :post, :headers => {}
123
-
124
- To build a paginated request use build_paginated_request:
125
- request_context = solr.build_paginated_request 1, 10, "select", ...
126
-
127
- == Updating Solr
128
- Updating is done using native Ruby objects. Hashes are used for single documents and arrays are used for a collection of documents (hashes). These objects get turned into simple XML "messages". Raw XML strings can also be used.
129
-
130
- Single document via #add
131
- solr.add :id=>1, :price=>1.00
132
-
133
- Multiple documents via #add
134
- documents = [{:id=>1, :price=>1.00}, {:id=>2, :price=>10.50}]
135
- solr.add documents
136
-
137
- The optional +:add_attributes+ hash can also be used to set Solr "add" document attributes:
138
- solr.add documents, :add_attributes => {:commitWithin => 10}
139
-
140
- Raw commands via #update
141
- solr.update data: '<commit/>', headers: { 'Content-Type' => 'text/xml' }
142
- solr.update data: { optimize: true }.to_json, headers: { 'Content-Type' => 'application/json' }
143
-
144
- When adding, you can also supply "add" xml element attributes and/or a block for manipulating other "add" related elements (docs and fields) by calling the +xml+ method directly:
145
-
146
- doc = {:id=>1, :price=>1.00}
147
- add_attributes = {:allowDups=>false, :commitWithin=>10}
148
- add_xml = solr.xml.add(doc, add_attributes) do |doc|
149
- # boost each document
150
- doc.attrs[:boost] = 1.5
151
- # boost the price field:
152
- doc.field_by_name(:price).attrs[:boost] = 2.0
153
- end
154
-
155
- Now the "add_xml" object can be sent to Solr like:
156
- solr.update :data => add_xml
157
-
158
- ===Deleting
159
- Delete by id
160
- solr.delete_by_id 1
161
- or an array of ids
162
- solr.delete_by_id [1, 2, 3, 4]
163
-
164
- Delete by query:
165
- solr.delete_by_query 'price:1.00'
166
- Delete by array of queries
167
- solr.delete_by_query ['price:1.00', 'price:10.00']
168
-
169
- ===Commit / Optimize
170
- solr.commit, :commit_attributes => {}
171
- solr.optimize, :optimize_attributes => {}
172
-
173
- == Response Formats
174
- The default response format is Ruby. When the +:wt+ param is set to +:ruby+, the response is eval'd resulting in a Hash. You can get a raw response by setting the +:wt+ to +"ruby"+ - notice, the string -- not a symbol. RSolr will eval the Ruby string ONLY if the :wt value is :ruby. All other response formats are available as expected, +:wt=>'xml'+ etc..
175
-
176
- ===Evaluated Ruby:
177
- solr.get 'select', :params => {:wt => :ruby} # notice :ruby is a Symbol
178
- ===Raw Ruby:
179
- solr.get 'select', :params => {:wt => 'ruby'} # notice 'ruby' is a String
180
- ===XML:
181
- solr.get 'select', :params => {:wt => :xml}
182
- ===JSON (default):
183
- solr.get 'select', :params => {:wt => :json}
184
-
185
- ==Related Resources & Projects
186
- * {RSolr Google Group}[http://groups.google.com/group/rsolr] -- The RSolr discussion group
187
- * {rsolr-ext}[http://github.com/mwmitchell/rsolr-ext] -- An extension kit for RSolr
188
- * {rsolr-direct}[http://github.com/mwmitchell/rsolr-direct] -- JRuby direct connection for RSolr
189
- * {rsolr-nokogiri}[http://github.com/mwmitchell/rsolr-nokogiri] -- Gives RSolr Nokogiri for XML generation.
190
- * {SunSpot}[http://github.com/sunspot/sunspot] -- An awesome Solr DSL, built with RSolr
191
- * {Blacklight}[http://blacklightopac.org] -- A "next generation" Library OPAC, built with RSolr
192
- * {java_bin}[http://github.com/kennyj/java_bin] -- Provides javabin/binary parsing for RSolr
193
- * {Solr}[http://lucene.apache.org/solr/] -- The Apache Solr project
194
- * {solr-ruby}[http://wiki.apache.org/solr/solr-ruby] -- The original Solr Ruby Gem!
195
-
196
- == Note on Patches/Pull Requests
197
- * Fork the project.
198
- * Make your feature addition or bug fix.
199
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
200
- * Commit, do not mess with rakefile, version, or history
201
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
202
- * Send me a pull request. Bonus points for topic branches.
203
-
204
- ==Contributors
205
- * Nathan Witmer
206
- * Magnus Bergmark
207
- * shima
208
- * Randy Souza
209
- * Mat Brown
210
- * Jeremy Hinegardner
211
- * Denis Goeury
212
- * shairon toledo
213
- * Rob Di Marco
214
- * Peter Kieltyka
215
- * Mike Perham
216
- * Lucas Souza
217
- * Dmitry Lihachev
218
- * Antoine Latter
219
- * Naomi Dushay
220
-
221
- ==Author
222
-
223
- Matt Mitchell <mailto:goodieboy@gmail.com>
224
-
225
- ==Copyright
226
-
227
- Copyright (c) 2008-2010 Matt Mitchell. See LICENSE for details.