Giter Club home page Giter Club logo

rsolr's Introduction

RSolr

A simple, extensible Ruby client for Apache Solr.

Documentation

The code docs www.rubydoc.info/gems/rsolr

Installation:

gem install rsolr

Example:

require 'rsolr'

# Direct connection
solr = RSolr.connect :url => 'http://solrserver.com'

# Connecting over a proxy server
solr = RSolr.connect :url => 'http://solrserver.com', :proxy=>'http://user:[email protected]:8080'

# Using an alternate Faraday adapter
solr = RSolr.connect :url => 'http://solrserver.com', :adapter => :em_http

# Using a custom Faraday connection
conn = Faraday.new do |faraday|
  faraday.response :logger                  # log requests to STDOUT
  faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
end
solr = RSolr.connect conn, :url => 'http://solrserver.com'

# send a request to /select
response = solr.get 'select', :params => {:q => '*:*'}

# send a request to /catalog
response = solr.get 'catalog', :params => {:q => '*:*'}

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.

The response also exposes 2 attribute readers (for any :wt value), :request and :response. Both are Hash objects with symbolized keys.

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..

The :response attribute contains the original response. This object contains the :status, :body and :headers keys.

Request formats

By default, RSolr uses the Solr JSON command format for all requests.

RSolr.connect :url => 'http://solrserver.com', update_format: :json # the default
# or
RSolr.connect :url => 'http://solrserver.com', update_format: :xml

Timeouts

The read and connect timeout settings can be set when creating a new instance of RSolr, and will be passed on to underlying Faraday instance:

solr = RSolr.connect(:timeout => 120, :open_timeout => 120)

Retry 503s

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.

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).

solr = RSolr.connect(:retry_503 => 1, :retry_after_limit => 1)

For additional control, consider using a custom Faraday connection (see above) using its ‘retry` middleware.

Querying

Use the #get / #post method to send search requests to the /select handler:

response = solr.get 'select', :params => {
  :q=>'washington',
  :start=>0,
  :rows=>10
}
response["response"]["docs"].each{|doc| puts doc["id"] }

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. When an array is used, multiple parameters *with the same name* are generated for the Solr query. Example:

solr.get 'select', :params => {:q=>'roses', :fq=>['red', 'violet']}

The above statement generates this Solr query:

select?q=roses&fq=red&fq=violet

Pagination

To paginate through a set of Solr documents, use the paginate method:

solr.paginate 1, 10, "select", :params => {:q => "test"}

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.

The paginate method returns WillPaginate ready “docs” objects, so for example in a Rails application, paginating is as simple as:

<%= will_paginate @solr_response["response"]["docs"] %>

Method Missing

The RSolr::Client class also uses method_missing for setting the request handler/path:

solr.paintings :params => {:q=>'roses', :fq=>['red', 'violet']}

This is sent to Solr as:

paintings?q=roses&fq=red&fq=violet

This works with pagination as well:

solr.paginate_paintings 1, 10, {:q=>'roses', :fq=>['red', 'violet']}

Using POST for Search Queries

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:

response = solr.music :data => {:q => "*:*"}

The :data hash is serialized as a form-encoded query string, and the correct content-type headers are sent along to Solr.

Sending HEAD Requests

There may be cases where you’d like to send a HEAD request to Solr:

solr.head("admin/ping").response[:status] == 200

Sending HTTP Headers

Solr responds to the request headers listed here: wiki.apache.org/solr/SolrAndHTTPCaches To send header information to Solr using RSolr, just use the :headers option:

response = solr.head "admin/ping", :headers => {"Cache-Control" => "If-None-Match"}

Building a Request

RSolr::Client provides a method for building a request context, which can be useful for debugging or logging etc.:

request_context = solr.build_request "select", :data => {:q => "*:*"}, :method => :post, :headers => {}

To build a paginated request use build_paginated_request:

request_context = solr.build_paginated_request 1, 10, "select", ...

Updating Solr

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.

Single document via #add

solr.add :id=>1, :price=>1.00

Multiple documents via #add

documents = [{:id=>1, :price=>1.00}, {:id=>2, :price=>10.50}]
solr.add documents

The optional :add_attributes hash can also be used to set Solr “add” document attributes:

solr.add documents, :add_attributes => {:commitWithin => 10}

Raw commands via #update

solr.update data: '<commit/>', headers: { 'Content-Type' => 'text/xml' }
solr.update data: { optimize: true }.to_json, headers: { 'Content-Type' => 'application/json' }

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:

doc = {:id=>1, :price=>1.00}
add_attributes = {:allowDups=>false, :commitWithin=>10}
add_xml = solr.xml.add(doc, add_attributes) do |doc|
  # boost each document
  doc.attrs[:boost] = 1.5
  # boost the price field:
  doc.field_by_name(:price).attrs[:boost] = 2.0
end

Now the “add_xml” object can be sent to Solr like:

solr.update :data => add_xml

Deleting

Delete by id

solr.delete_by_id 1

or an array of ids

solr.delete_by_id [1, 2, 3, 4]

Delete by query:

solr.delete_by_query 'price:1.00'

Delete by array of queries

solr.delete_by_query ['price:1.00', 'price:10.00']

Commit / Optimize

solr.commit, :commit_attributes => {}
solr.optimize, :optimize_attributes => {}

Response Formats

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..

Evaluated Ruby:

solr.get 'select', :params => {:wt => :ruby} # notice :ruby is a Symbol

Raw Ruby:

solr.get 'select', :params => {:wt => 'ruby'} # notice 'ruby' is a String

XML:

solr.get 'select', :params => {:wt => :xml}

JSON (default):

solr.get 'select', :params => {:wt => :json}

Related Resources & Projects

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history (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)

  • Send me a pull request. Bonus points for topic branches.

Contributors

  • Nathan Witmer

  • Magnus Bergmark

  • shima

  • Randy Souza

  • Mat Brown

  • Jeremy Hinegardner

  • Denis Goeury

  • shairon toledo

  • Rob Di Marco

  • Peter Kieltyka

  • Mike Perham

  • Lucas Souza

  • Dmitry Lihachev

  • Antoine Latter

  • Naomi Dushay

Author

Matt Mitchell <[email protected]>

Copyright © 2008-2010 Matt Mitchell. See LICENSE for details.

rsolr's People

Contributors

cbeer avatar cgalarza avatar copiousfreetime avatar expajp avatar genandre avatar jcoleman avatar jcoyne avatar jrochkind avatar kjir avatar koic avatar mange avatar mbklein avatar mejackreed avatar mwmitchell avatar ndushay avatar nz avatar ojlyytinen avatar pofmagicfingers avatar rks avatar robdimarco avatar ronan-mch avatar rosenfeld avatar scottolsen avatar serggl avatar shairontoledo avatar tpendragon avatar udaykadaboina avatar valve avatar vipulnsward avatar zerowidth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rsolr's Issues

Facet items not working properly

Using Rails 2.3.2, Ruby 1.8.7, windows Vista, Solr 1.4

Playing with rsolr ext and have a query like this:

solr = RSolr.connect :url => 'http://localhost:8982/solr'
solr_params = {
:per_page=>2,
:queries=>':',
:facets=>{:fields=>['project_id_facet', 'source_type_facet']},
:echoParams => 'EXPLICIT'
}

@response = solr.find solr_params

In my view I have the code to output the facet values and counts:

<% @response.facets.each do |facet| %>

<%= facet.name %>



<% facet.items.each do |item| %>
<%= "#{facet.name}::#{item.value} (#{item.hits})" %>
<% end %>
<% end %>

With the stock code I get a result like:
source_type_facet
source_type_facet:: () source_type_facet:: () source_type_facet:: () source_type_facet:: () source_type_facet:: ()
project_id_facet
project_id_facet:: ()

The problem is in the facets method in RSolr::Ext::Response::Facets.

If I change this code:
(values_and_hits.size/2).times do |index|
items << FacetItem.new(values_and_hits[index_2], values_and_hits[index_2+1])
end

to:

values_and_hits.each do |key, value|
items << FacetItem.new(key, value)
end

I get the proper results:
source_type_facet
source_type_facet::ticket (4324) source_type_facet::commit (1092) source_type_facet::portal (34) source_type_facet::native (43) source_type_facet::build (211) source_type_facet::timesheet (7) source_type_facet::wiki (1127) source_type_facet::code_review (714) source_type_facet::general (266) source_type_facet::email (189)
project_id_facet
project_id_facet::1 (4637) project_id_facet::2 (1192) project_id_facet::3 (2178)

Anyone else see a similar issue?

If I inspect the value_and_hits variable its a simple hash like this:
{"1"=>4637, "2"=>1192, "3"=>2178}

So, I can't see how the original code can work at all.

rsolr doesn't work on rubinius

Currently the gem doesn't work on Rubinius the issue is on PaginatedDocSet where start and total are actual fields in Rubinius Array implementation, its an easy fix just prefix those fields.

Pull request would be attached

Deprecation Warning about ActiveSupport::Concern and RSolr::Connection

Hey guys,

I'm getting this deprecation warning.

DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in RSolr::Connection instead. (called from <top (required)> at /Library/WebServer/Documents/store/config/environment.rb:5)

I'm using sunspot_rails gem, which uses rsolr. I took a look at RSolr::Connection but found nothing related (on edge, maybe 1.0.7 has code that I didn't see).

I'm seeing this error using sunspot_rails gem with Rails 3.2.1. Did anybody else noticed this?

Add License information to Gemspec

This will make it show up on rubygems.org. I'm doing due diligence on our gems and need to find out the licenses for all the gems. Having it show up on rubygems.org cuts out the step of having to go to the github repo.

Solr response not found

CODE:

require 'rubygems'
Gem.clear_paths
ENV['GEM_HOME'] = '/usr/local/jruby-1.5.1/lib/ruby/gems/1.8'
ENV['GEM_PATH'] = '/usr/local/jruby-1.5.1/lib/ruby/gems/1.8'

require 'rsolr'

solr = RSolr.connect :url => 'http://localhost:8983/solr'

send a request to /select

response = solr.get 'select', :params => {:wt => 'ruby', :q => 'body:george'}

response = solr.post "select", {}, :q=>"George"

response = solr.get 'select', :params => {:q => 'body:George'}

ERROR:
/usr/local/jruby-1.5.1/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/connection/requestable.rb:39:in request': Solr Response: Not Found (RSolr::RequestError) from /usr/local/jruby-1.5.1/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/client.rb:34:inrequest'
from /usr/local/jruby-1.5.1/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/client.rb:16:in method_missing' from ./rp5testsolr.rb:17 from ./rp5testsolr.rb:33:inload'
from /Library/Ruby/Gems/1.8/gems/ruby-processing-1.0.9/lib/ruby-processing/runners/base.rb:33:in `load_and_run_sketch'
from /Library/Ruby/Gems/1.8/gems/ruby-processing-1.0.9/lib/ruby-processing/runners/run.rb:7

Can you see what's going wrong?
I have solr running locally.

deprecation warning question

When I run Blacklight's own tests, I get this deprecation warning output to stdout/stderr:

 DEPRECATION WARNING: RSolr::Pagination / pagination functionality will be removed in 1.1.0.

It's not clear to me exactly what line in Blacklight is causing this output. As far as I know, Blacklight is not in fact using any "RSolr::Pagination / pagination functionality". But perhaps it is accidentally?

Can you give me any hints as to what usage will cause this message to be output, or what line in RSolr code outputs this so I can try to reverse engineer it myself? I'd like to fix Blacklight's calling of RSolr so it will not result in this deprecation warning.

SystemStackError when evaluating huge responses as :ruby

When i do a get select request and the response is huge enough, an exception is thrown:

(eval):0: stack level too deep (SystemStackError)

This happens only when I specify the response to be evaluated as a ruby object:

:wt => :ruby

Ruby version: 1.9.2
Source script:

require 'rubygems'
require 'rsolr'

solr = RSolr.connect :url => 'http://localhost:8982/solr'

puts response = solr.get('select', :params => {
:wt => :ruby,
:fq => ['type:Article', 'review_im:46'],
:start => 0,
:rows => 0,
:facet => true,
"f.source_i.facet.mincount" => 1,
"facet.field" => ['source_i', 'language_i', 'publication_types_im', 'features_im', 'locations_im', 'keyphrases_im', 'journal_i', 'authors_im', 'year_i'],
"f.language_i.facet.mincount" => 1,
"f.publication_types_im.facet.mincount" => 1,
"f.features_im.facet.mincount" => 1,
"f.locations_im.facet.limit" => 30,
"f.locations_im.facet.mincount" => 1,
"f.keyphrases_im.facet.limit" => 30,
"f.keyphrases_im.facet.mincount" => 1,
"f.journal_i.facet.sort" => true,
"f.journal_i.facet.limit" => -1,
"f.journal_i.facet.mincount" => 1,
"f.authors_im.facet.sort" => true,
"f.authors_im.facet.limit" => -1,
"f.authors_im.facet.mincount" => 1,
"f.year_i.facet.limit" => 10,
"f.year_i.facet.mincount" => 1,
"q" => ':'
}, :headers => {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"})

The output from Solr is perfectly valid, and here is the response that breaks RSolr:
http://da.qcri.org/solr-response-46-70000.txt

undefined method `q' for :spellcheck:Symbol

How do you use parameter names in rsolr select request which contains dots? For example fl.highlight or q.spellcheck? I always the the following error when trying to use dots in parameters:

undefined method q' for :spellcheck:Symbol`

and in general it would be nice to have select requests which are complexer in the documentation.

Errno::ECONNREFUSED

Heya, we have implemented sunspot_rails along with Rsolr for a website.

Rsolr is the newest version, along with sunspot_rails etc.

The solr instance starts fine, and reindex is also done well, but suddenly, this error occurs:

ERROR MESSAGE:
Errno::ECONNREFUSED: Connection refused - {:data=>"fq=type%3ARefinery%5C%3A%5C%3AWayfinders%5C%3A%5C%3AProject&q=klean&fl=%2A+score&qf=name_text+city_text+courses_text&defType=edismax&start=0&rows=30", :method=>:post, :params=>{:wt=>:ruby}, :query=>"wt=ruby", :headers=>{"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, :path=>"select", :uri=>#<URI::HTTP:0x23ef0060 URL:http://localhost:8983/solr/default/select?wt=ruby>, :open_timeout=>nil, :read_timeout=>nil, :retry_503=>nil, :retry_after_limit=>nil}

WHERE:
search#index

app/controllers/search_controller.rb:4

Full Backtrace

[GEM_ROOT]/gems/rsolr-1.0.10/lib/rsolr/connection.rb:19
[GEM_ROOT]/gems/rsolr-1.0.10/lib/rsolr/connection.rb:14
[GEM_ROOT]/gems/rsolr-1.0.10/lib/rsolr/client.rb:182
[GEM_ROOT]/gems/rsolr-1.0.10/lib/rsolr/client.rb:176
[GEM_ROOT]/gems/sunspot_rails-2.1.0/lib/sunspot/rails/solr_instrumentation.rb:16
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/notifications.rb:123
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/notifications.rb:123
[GEM_ROOT]/gems/sunspot_rails-2.1.0/lib/sunspot/rails/solr_instrumentation.rb:15
(eval):2
[GEM_ROOT]/gems/sunspot-2.1.0/lib/sunspot/search/abstract_search.rb:45
[GEM_ROOT]/gems/sunspot_rails-2.1.0/lib/sunspot/rails/searchable.rb:344
[GEM_ROOT]/gems/sunspot_rails-2.1.0/lib/sunspot/rails/searchable.rb:158
app/controllers/search_controller.rb:4
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal/implicit_render.rb:4
[GEM_ROOT]/gems/actionpack-3.2.14/lib/abstract_controller/base.rb:167
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal/rendering.rb:10
[GEM_ROOT]/gems/actionpack-3.2.14/lib/abstract_controller/callbacks.rb:18
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:425
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:405
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:385
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:81
[GEM_ROOT]/gems/actionpack-3.2.14/lib/abstract_controller/callbacks.rb:17
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal/rescue.rb:29
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal/instrumentation.rb:30
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/notifications.rb:123
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/notifications/instrumenter.rb:20
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/notifications.rb:123
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal/instrumentation.rb:29
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal/params_wrapper.rb:207
[GEM_ROOT]/gems/activerecord-3.2.14/lib/active_record/railties/controller_runtime.rb:18
[GEM_ROOT]/gems/actionpack-3.2.14/lib/abstract_controller/base.rb:121
[GEM_ROOT]/gems/actionpack-3.2.14/lib/abstract_controller/rendering.rb:45
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal.rb:203
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal/rack_delegation.rb:14
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_controller/metal.rb:246
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/routing/route_set.rb:73
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/routing/route_set.rb:73
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/routing/route_set.rb:36
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:68
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:56
[GEM_ROOT]/gems/journey-1.0.4/lib/journey/router.rb:56
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/routing/route_set.rb:608
[GEM_ROOT]/gems/warden-1.2.3/lib/warden/manager.rb:35
[GEM_ROOT]/gems/warden-1.2.3/lib/warden/manager.rb:34
[GEM_ROOT]/gems/warden-1.2.3/lib/warden/manager.rb:34
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/best_standards_support.rb:17
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/etag.rb:23
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/conditionalget.rb:25
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/head.rb:14
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/params_parser.rb:21
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/flash.rb:242
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/cookies.rb:341
[GEM_ROOT]/gems/dragonfly-0.9.15/lib/dragonfly/cookie_monster.rb:9
[GEM_ROOT]/gems/activerecord-3.2.14/lib/active_record/query_cache.rb:64
[GEM_ROOT]/gems/activerecord-3.2.14/lib/active_record/connection_adapters/abstract/connection_pool.rb:479
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/callbacks.rb:28
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:405
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:405
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:385
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/callbacks.rb:81
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/callbacks.rb:27
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/remote_ip.rb:31
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/debug_exceptions.rb:16
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/show_exceptions.rb:56
[GEM_ROOT]/gems/railties-3.2.14/lib/rails/rack/logger.rb:32
[GEM_ROOT]/gems/railties-3.2.14/lib/rails/rack/logger.rb:16
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/tagged_logging.rb:22
[GEM_ROOT]/gems/railties-3.2.14/lib/rails/rack/logger.rb:16
[GEM_ROOT]/gems/actionpack-3.2.14/lib/action_dispatch/middleware/request_id.rb:22
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/methodoverride.rb:21
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/runtime.rb:17
[GEM_ROOT]/gems/activesupport-3.2.14/lib/active_support/cache/strategy/local_cache.rb:72
[GEM_ROOT]/gems/rack-1.4.5/lib/rack/lock.rb:15
[GEM_ROOT]/gems/dragonfly-0.9.15/lib/dragonfly/middleware.rb:13
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:136
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:245
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:185
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:66
[GEM_ROOT]/gems/rack-cache-1.2/lib/rack/cache/context.rb:51
[GEM_ROOT]/gems/railties-3.2.14/lib/rails/engine.rb:484
[GEM_ROOT]/gems/railties-3.2.14/lib/rails/application.rb:231
[GEM_ROOT]/gems/railties-3.2.14/lib/rails/railtie/configurable.rb:30
/home/klean/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.14/lib/phusion_passenger/rack/thread_handler_extension.rb:77
/home/klean/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.14/lib/phusion_passenger/request_handler/thread_handler.rb:140
/home/klean/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.14/lib/phusion_passenger/request_handler/thread_handler.rb:108
/home/klean/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-4.0.14/lib/phusion_passenger/request_handler.rb:441

search_controller.rb

class SearchController < ApplicationController
  def index

    @project_search = Refinery::Wayfinders::Project.search do
      fulltext params[:search]
    end

    @club_search = Refinery::Wayfinders::Club.search do
      fulltext params[:search]
    end

    @page_search = Refinery::Page.search do
      with(:show_in_menu, false)
      fulltext params[:search]
    end

    @search_word = params[:search]
    @project_result = @project_search.results
    @club_result = @club_search.results
    @page_result = @page_search.results
    @results = (@club_result.count + @project_result.count + @page_result.count)
  end
end

It occurs very randomly. Normally the search works fine, we can search, get results, etc. But then it suddenly fails.

This problem has occurred with version 1.0.7, 1.0.8, 1.0.9, 1.0.10.pre and the newest version.

When this error is triggered, the create/update functions of Refinery CMS wont work.

Would be glad to get some help on this, since the site aint really functioning when the search fails.

Thanks in advance

Regards

How to properly escape ":" in the "q" param

Hi,

I'm (happily) using RSolr to make request to my Solr server.

Sometimes, people write a query string with a ":" in it, and the previous chars are then treated as a field name rather than a basic string.

What would be the proper way to escape this ":" ?

If I do something like this in the params hash : solr_params[:q] = params[:q].gsub(/:/,'\:') Solr responds with a JSON blob where the backslash is double escaped : {'responseHeader'=>{'status'=>0,'QTime'=>2,'params'=>{'start'=>'0','q'=>'ex\\: Nice','wt'=>'ruby','rows'=>'15'}},'response'=>{'numFound'=>0,'start'=>0,'docs'=>[]}}

Thanks for any help.

Unreadable errors

Any errors thrown are unreadable since most extra characters and all whitespace is removed from the message somewhere between what Solr sends and what is displayed in the Ruby output. This makes for extra unreadable errors when a stack trace was returned from Java since you get an error message of several hundred characters long as one word.

I think it would be great if the errors was formatted better, and if the error class could contain the HTTP context in it, so a custom rescue block should be able to inspect the URL that caused the error, see more of the returned markup, etc.

Non-blocking API?

Hi,
Does RSolr support non-blocking API?
I read some of code in it and I found it uses net/http. There's no non-blocking API in it, right? So I can't send multiple requests to Solr parallel.
Would you mind to add this feature? You could use Faraday to make this work easier.
Thanks!

RSolr::Client shouldn't try to modify the string of the url param

Passing a frozen String (such as the heroku WEBSOLR_URL ENV variable) as the url param to the RSolr::Client initializer fails as it try to modify

rsolr-1.0.0/lib/rsolr/client.rb:9
url = options[:url] || 'http://127.0.0.1:8983/solr/'
url << "/" unless url[-1] == ?/

I don't know if this was the expected behavior, but I think the initializer have to clone the url string before trying to modify it.

Invalid Date String error

When I add a document with a date to my Solr index, the date isn't automatically converted to the required ISO 8601 format:

doc = {
  :id=>1,
  :my_string=>'foo',
  :my_int=>42,
  :my_bool=>true,
  :my_date=>Date.new(2013, 1, 1)
}
solr.add doc

The above example attempts to set the value of the my_date field to 2013-01-01, which results in an error:

{'responseHeader'=>{'status'=>400,'QTime'=>1},'error'=>{'msg'=>'Invalid Date String:\'2013-01-01\'','code'=>400}}

However, if I manually convert the date, it works fine:

doc = {
  :id=>1,
  :my_string=>'foo',
  :my_int=>42,
  :my_bool=>true,
  :my_date=>Date.new(2013, 1, 1).to_time.utc.iso8601
}
solr.add doc

Since Solr only uses ISO 8601 format, is it possible to have RSolr convert Ruby Date and Time objects to the required format automatically?

I would be happy to work on a patch if you think this is a good idea.

calculate_start_and_rows method does not take into account that request[:params] maybe nil

The issue is present in the master branch as of commit 548985d.

The add method ideally shouldn't require any opts passed let alone a hash returned by opts[:params].

solr.add([{:id => 1983, :name => "Thomas"}])
NoMethodError: undefined method merge!' for nil:NilClass from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/whiny_nil.rb:52:inmethod_missing'
from /usr/local/lib/ruby/gems/1.8/gems/rsolr-1.0.0.beta3/lib/rsolr/connectable.rb:123:in calculate_start_and_rows' from /usr/local/lib/ruby/gems/1.8/gems/rsolr-1.0.0.beta3/lib/rsolr/connectable.rb:58:inbuild_request'
from /usr/local/lib/ruby/gems/1.8/gems/rsolr-1.0.0.beta3/lib/rsolr/connectable.rb:32:in send_request' from /usr/local/lib/ruby/gems/1.8/gems/rsolr-1.0.0.beta3/lib/rsolr/client.rb:126:insend_request'
from (eval):2:in post' from /usr/local/lib/ruby/gems/1.8/gems/rsolr-1.0.0.beta3/lib/rsolr/client.rb:35:inupdate'
from /usr/local/lib/ruby/gems/1.8/gems/rsolr-1.0.0.beta3/lib/rsolr/client.rb:52:in `add'
from (irb):21

steal my curl backend

Performance Benchmarks:
https://gist.github.com/674805

I pulled rsolr into my own library, which is going to be drastically different (eventually). That said, you can pick through my changes and are welcome to yank my "streamly.rb" file. It's based on my StreamlyFFI/CurlFFI gems. So, it's a cross-ruby (jruby, rbx, mri, ...) compatible libCurl HTTP interface.

It should be a pretty simple yank and drop into rsolr.

Change in escaping

::solr_escape which is now replacing the deprecated ::escape has one difference:

>   RSolr.escape("foo bar")
=> "foo\\ bar"
>   RSolr.solr_escape("foo bar")
=> "foo bar"

Is this significant? Or are we supposed to do to field:foo AND field:bar in our queries?
It's also not escaping floats as it used to:

>   RSolr.escape("1.11")
=> "1\\.11"
>   RSolr.solr_escape("1.11")
=> "1.11"

which affects projectblacklight/blacklight#1126

evaluate_ruby_response causes duplicate key warnings

With ruby 2.2

(byebug) n
(eval):1: warning: duplicated key at line 1 ignored: "active_fedora_model_ssi"
(eval):1: warning: duplicated key at line 1 ignored: "location_label_sim"
(eval):1: warning: duplicated key at line 1 ignored: "creator_label_sim"
(eval):1: warning: duplicated key at line 1 ignored: "lc_subject_label_sim"
(eval):1: warning: duplicated key at line 1 ignored: "publisher_sim"
(eval):1: warning: duplicated key at line 1 ignored: "year_iim"
(eval):1: warning: duplicated key at line 1 ignored: "form_of_work_label_sim"
(eval):1: warning: duplicated key at line 1 ignored: "collection_label_ssim"
"{'responseHeader'=>{'status'=>0,'QTime'=>3,'params'=>{'sort'=>'score desc, date_si desc, creator_label_si asc','qf'=>'title_tesim lc_subject_label_tesim','facet.field'=>['active_fedora_model_ssi','location_label_sim','creator_label_sim','lc_subject_label_sim','publisher_sim','year_iim','form_of_work_label_sim','collection_label_ssim'],'qt'=>'search','wt'=>'ruby','fq'=>'has_model_ssim:(\"Image\")','rows'=>'10'}},'response'=>{'numFound'=>1,'start'=>0,'maxScore'=>1.0,'docs'=>[{'system_create_dtsi'=>'2015-03-04T19:18:30Z','system_modified_dtsi'=>'2015-03-04T19:18:30Z','active_fedora_model_ssi'=>'Image','has_model_ssim'=>['Image'],'id'=>'47/3b/6e/c5/473b6ec5-0e40-48a8-96d1-f683c998f3be','object_profile_ssm'=>['{\"id\":\"47/3b/6e/c5/473b6ec5-0e40-48a8-96d1-f683c998f3be\",\"identifier\":[],\"accession_number\":[],\"title\":null,\"alternative\":[],\"creator\":[],\"collector\":[],\"contributor\":[],\"description\":[],\"latitude\":[],\"language\":[],\"longitude\":[],\"location\":[],\"lc_subject\":[],\"publisher\":[],\"work_type\":[],\"series_name\":[],\"issued\":[],\"issued_start\":[],\"issued_end\":[],\"created_start\":[],\"created_end\":[],\"date_other\":[],\"form_of_work\":[],\"citation\":[],\"digital_origin\":[],\"note\":[],\"description_standard\":[],\"extent\":[],\"sub_location\":[],\"record_origin\":[],\"use_restrictions\":[]}'],'_version_'=>1494741640676376576,'timestamp'=>'2015-03-04T19:18:32.376Z','score'=>1.0}]},'facet_counts'=>{'facet_queries'=>{},'facet_fields'=>{'active_fedora_model_ssi'=>['Image',1],'location_label_sim'=>[],'creator_label_sim'=>[],'lc_subject_label_sim'=>[],'publisher_sim'=>[],'year_iim'=>[],'form_of_work_label_sim'=>[],'collection_label_ssim'=>[],'active_fedora_model_ssi'=>['Image',1],'location_label_sim'=>[],'creator_label_sim'=>[],'lc_subject_label_sim'=>[],'publisher_sim'=>[],'year_iim'=>[],'form_of_work_label_sim'=>[],'collection_label_ssim'=>[]},'facet_dates'=>{},'facet_ranges'=>{},'facet_intervals'=>{}}}\n"

Cannot use with Rails 3.0.10

4988a83 added a constraint on builder = 3.0.0 to the .gemspec. This is not compatible with Rails 3.0.10.

Any reason why builder was pulled in and locked to 3.0.0?

@adl9 ➜  rails3010app rvm:(-ruby-1.9.2)  bundle
Fetching gem metadata from http://rubygems.org/.........
Bundler could not find compatible versions for gem "builder":
  In Gemfile:
    rails (= 3.0.10) ruby depends on
      builder (~> 2.1.2) ruby

    rsolr (~> 1.0.3) ruby depends on
      builder (3.0.0)

RSolr::Error::Http - 400 Bad Request in Blacklight 2.8 and 2.9

See also: https://groups.google.com/forum/?fromgroups#!topic/blacklight-development/GbcTM75Mox4

Blacklight 2.8 / 2.9 use RSolr 1.0.0 whereas Blacklight 2.7 uses RSolr 0.12.1.
My Blacklight installations uses a Solr index which is behind an Apache
web server using an AJP connector. My BL solr.yml config file contains:

development:
url: http://dev.fedapps.toldark.com.au:80/solr

All is copacetic in BL 2.7. However BL 2.8 and 2.9 fail on startup:

Processing ApplicationController#index (for 127.0.0.1 at 2011-05-09 08:24:24)
[GET]
Parameters: {"action"=>"index", "controller"=>"catalog"}

RSolr::Error::Http (RSolr::Error::Http - 400 Bad Request
Error:

Query:
select?f.gemet_facet.facet.limit=11&qt=search&f.author_facet.facet.limit=11&f.rights_facet.facet.limit=11&f.agrovoc_facet.facet.limit=11&f.decade_facet.facet.limit=11&f.year_facet.facet.limit=11&rows=10&f.subject_author_facet.facet.limit=11&f.publisher_facet.facet.limit=11&facet.field=agrovoc_facet&facet.field=gemet_facet&facet.field=subject_author_facet&facet.field=author_facet&facet.field=decade_facet&facet.field=year_facet&facet.field=publisher_facet&facet.field=geographic_facet&facet.field=rights_facet&wt=ruby&f.geographic_facet.facet.limit=11

Backtrace:
/opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:209:in adapt_response' /opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:152:inexecute'
/opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:146:in send_and_receive' /opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-ext-1.0.0/lib/rsolr-ext/client.rb:20:infind'

Further details from script/console:

BL 2.9:

Loading development environment (Rails 2.3.11)
This application has Blacklight version 2.9.0 installed

Blacklight.solr
=> #<RSolr::Client:0x2b5517f8aba0 @uri=#<URI::HTTP:0x2b5517f67a60
URL:http://dev.fedapps.toldark.com.au/solr/>,
@options={:url=>"http://dev.fedapps.toldark.com.au:80/solr/"},
@connection=#RSolr::Connection:0x2b5517fac5e8>
Blacklight.solr.ping
RSolr::Error::Http: RSolr::Error::Http - 400 Bad Request
Error:

Query: admin/ping?wt=ruby

Backtrace:
/opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:209:in adapt_response' /opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:152:inexecute'
/opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:146:in send_and_receive' (eval):2:inget' /opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-ext-1.0.0/lib/rsolr-ext/client.rb:45:in ping' (irb):2:inirb_binding'
/opt/ruby/1.8.7/lib/ruby/1.8/irb/workspace.rb:52:in irb_binding' /opt/ruby/1.8.7/lib/ruby/1.8/irb/workspace.rb:52 from /opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:209:inadapt_response' from
/opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:152:in execute' from /opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-1.0.0/lib/rsolr/client.rb:146:in send_and_receive' from (eval):2:in get' from /opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rsolr-ext-1.0.0/lib/rsolr-ext/client.rb:45:inping' from (irb):2

Blacklight.solr.connection
=> #<RSolr::Connection:0x2b5517fac5e8 @http=#<Net::HTTP
dev.fedapps.toldark.com.au:80 open=false>>
exit

BL 2.7:

Loading development environment (Rails 2.3.5)
/opt/ruby/1.8.7/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning:
Gem::Dependency#version_requirements is deprecated and will be removed on or
after August 2010. Use #requirement
This application has Blacklight version 2.7.0 installed

Blacklight.solr
=> #<RSolr::Client:0x2b161c79a8d0
@connection=#<RSolr::Connection::NetHttp:0x2b161c79ebd8
@opts={:adapter=>:curb, :url=>"http://dev.fedapps.toldark.com.au:80/solr"},
@uri=#<URI::HTTP:0x2b161c7929f0 URL:http://dev.fedapps.toldark.com.au/solr>>>
Blacklight.solr.ping
=> {"responseHeader"=>{"QTime"=>13, "params"=>{"subject_pf"=>"\n
subject_author_unstem_search^10000\n subject_author_t^5000\n
gemet_unstem_search^7500\n gemet_t^3750\n

...

Blacklight.solr.connection
=> #<RSolr::Connection::NetHttp:0x2b161c79ebd8 @connection=#<Net::HTTP
dev.fedapps.toldark.com.au:80 open=false>, @opts={:adapter=>:curb,
:url=>"http://dev.fedapps.toldark.com.au:80/solr"},
@uri=#<URI::HTTP:0x2b161c7929f0 URL:http://dev.fedapps.toldark.com.au/solr>>
exit

Apache log:

For BL 2.7 ping request:
192.168.198.150 - - [18/May/2011:15:57:35 +1000] "GET /solr/admin/ping?wt=ruby
HTTP/1.1" 200 3480 "-" "-"

For BL 2.9 ping request:
192.168.198.150 - - [18/May/2011:15:50:53 +1000] "GET
http://dev.fedapps.toldark.com.au/solr/admin/ping?wt=ruby HTTP/1.1" 400 - "-"
"-"

memory leaks?

I've tracked down a memory leak to rsolr, where I normally create some threads to push data into solr. The ruby process uses up all the memory, but If I comment out rsolr so the while loop just pops items off the queue, the app stays at a constant 22 mb of use. This loop is used to push in millions of docs into solr.

25.times do |t|
  threads << Thread.new do
    rsolr = RSolr.connect :url => (CONFIG[$env]["solr"] ||'http://localhost:8983/solr')
    while true
      a = $q.pop
      if a
        begin
          rsolr.add a
          $inserts += 1
        rescue Exception => e
          puts e
          $ecount += 1
        end
      end
    end
  end
end

Gemcutter gem?

Github gems are no more... I'm changing all my old github gems back to normal syntax... ERROR: could not find gem rsolr locally or in a repository ;)

Client#update broken

At least in the example/http.rb.

As I see it, the client tries to eval the response, which is just an XML string.

>> solr = RSolr.connect
>> solr.update File.read("solr/example/exampledocs/hd.xml")
SyntaxError: (eval):1:in `adapt_response': compile error
(eval):1: syntax error, unexpected '<'
<?xml version="1.0" encoding="UTF-8"?>
 ^
(eval):1: syntax error, unexpected tIDENTIFIER, expecting $end
<?xml version="1.0" encoding="UTF-8"?>
                            ^
    from ./lib/rsolr/client.rb:126:in `adapt_response'
from ./lib/rsolr/client.rb:35:in `eval'
from ./lib/rsolr/client.rb:126:in `adapt_response'
from ./lib/rsolr/client.rb:35:in `request'
from ./lib/rsolr/client.rb:22:in `update'
from (irb):6

pagination fails if :page is nil

If calling paginate with a nil page arg, the response object doesn't have the expected methods for pagination. Default page arg to 1 if page arg is nil.

RSolr::Response should expose http response headers

In order to do proper caching, a user needs access to the http response headers to grab "ETag" and "Last-Modified". Currently (as far as I can tell), those headers are not exposed when client.get is called. Can we get those exposed in RSolr::Response? I would be more than happy to provide an implementation if such an addition would be accepted.

base_uri and proxies

Hi,

I was having some strange behaviour with RSolr and proxies. I provided a proxy and the proxy was being used as the actual uri which was causing 400's. I narrowed it down to:

/lib/rsolr/client.rb line 28

def base_uri
    @proxy ? @proxy : @uri
end

this method can return a proxy if set, but this method is used below when constructing the :uri option. This means that the proxy uri is used to build the connection path.

def build_request path, opts
    ...
    opts[:uri] = base_uri.merge(path.to_s + (query ? "?#{query}" : "")) if base_uri
    ...
end

When connection.execute self, request_context gets called

h = http request_context[:uri], request_context[:proxy]

is called, and means that the uri and proxy have the same uri. Am I misunderstanding something here?

Anyway my fix was to do:

def base_uri
    @uri
end

which appears to work as expected for me.

'update'

line 67 of client.rb

'update' isn't a full path enough for it to know where to post the data to for adding new documents.

I had to hard code my path like so...
post 'http://localhost:8982/solr/update/', opts

configurable timeout

Especially when solr is optimizing a commit, it would be nice to be able to set a longer timeout for requests.
I keep running into timeout errors for requests because solr is working hard and doesn't answer within x seconds (takes about 60 seconds for me to get an answer via curl from commandline)

RSolr.escape doesn't work for dash

When the parameter is "aptrust-test:40110" it is escaped as "aptrust\\-test\\:40110", which causes an error:

'error'=>{'msg'=>'org.apache.solr.search.SyntaxError: Cannot parse \'my_field:aptrust\\-test\\:40110}

commitWithin didn't work

Hello,

I wanted to use commitWithin, so I tried:

connection.commitWithin(30000)

but that didn't work, so looking at the documentation, it seems the way to go is:

Solr.connection.commit :commit_attributes => {:commitWithin => 30000}

but although it seems to work, in solr I get:

WARNING: unexpected attribute commit/@commitWithin

How do I send a commit with commitWithin from rsolr? is it possible?

FYI: two warnings in 1.0.2

Hi,

Just to highlight a couple of warnings thrown up by Ruby192_p180:

a)

In lib/rsolr/cleint.rb, base_uri method

@Proxy || @uri

The "usual" way:

(@Proxy ||=nil) || @uri

fixes with no untoward side effects for me.

b)

In lib/rsolr/char.rb escape method (line 7) brackets around the gsub makes it go away.

Better error messages

Hey, I really like RSolr. The key problem that we're having with it is that the error messages are really opaque. It would be incredibly useful if in addition to returning the http status code information, you also scraped (or provided a hook for scraping) the page for the solr-specific error message.

Not that useful: 400 Bad Request

Much more useful: 400 Bad Request: Field foo does not exist in schema.

I'm happy to discuss further, and submit a patch, etc.

RSolr - Net:HTTP - EOFError

Hi,
first of all, thank you for your contribution, it's really useful.

I've been using your gem without any problems but recently I got this error from Net:HTTP library:

EOFError: End of file reached

Here is the full trace:

end of file reached
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:135:in `read_nonblock'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:135:in `rbuf_fill'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:2208:in `read_new'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1177:in `request'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1170:in `block in request'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:627:in `start'
/Users/fertapric/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:1168:in `request'
/Users/fertapric/.rvm/gems/ruby-1.9.2-p290/gems/rsolr-1.0.8/lib/rsolr/connection.rb:15:in `execute'
/Users/fertapric/.rvm/gems/ruby-1.9.2-p290/gems/rsolr-1.0.8/lib/rsolr/client.rb:166:in `execute'
/Users/fertapric/.rvm/gems/ruby-1.9.2-p290/gems/rsolr-1.0.8/lib/rsolr/client.rb:161:in `send_and_receive'
(eval):2:in `post'
/Users/fertapric/.rvm/gems/ruby-1.9.2-p290/gems/rsolr-1.0.8/lib/rsolr/client.rb:67:in `update'
/Users/fertapric/.rvm/gems/ruby-1.9.2-p290/gems/rsolr-1.0.8/lib/rsolr/client.rb:87:in `add'

And here is the xml that I'm trying to update:

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  <add>
    <doc>
      <field name=\"id\">4f9147b968403155190000204f9147b96840315519000022</field>
      <field name=\"user\">4f9147b96840315519000020</field>
      <field name=\"match\">4f9147b96840315519000022</field>
      <field name=\"name\">Fernando Tapia Rico</field>
      <field name=\"live\">false</field>
      <field name=\"latlng\">5.0,3.4</field>
      <field name=\"score\">90</field>
      <field name=\"count\">70</field>
    </doc>
  </add>"

I tried both

solr = RSolr.connect :url => 'http://solrserver.com'
solr.add document(Hash)

OR

solr.update(:data => document(XML))

and none of them worked.
The RSolr version I'm using is 1.0.8

Thanks for you help in advance
Cheers

Solr escaping is incorrect.

I think that #71 was really about missing an end quote, but the Solr escaping currently in RSolr is incorrect - it escapes too many characters and search results can be different with the incorrect escaping than with correct escaping. (e.g. inappropriately Solr escaped spaces can affect things).

Pull request to follow shortly.

Accents

I'm using UTF-8 in all: BD, Rails, HTTP etc.

But I'm having problems with accents in the search result. I had tested Solr directly, and what I found is something in RSolr. Any idea how I can solve this problem?

using http post for queries

This might be a bit obscure, but in some cases I'll have a really long query, so I'm going to use a POST rather than a GET for the searches.

These properly returns a hash:
Solr.connection.request '/select', {:q=>'foo'}
Solr.connection.request '/select', {:q=>'foo'}, :method=>:get

This returns a string:
Solr.connection.request '/select', {:q=>'foo'}, :method=>:post

because the response from the POST doesn't have :params so the adapt_response method doesn't eval it.

new release

last release was on 3/26, and it'd be nice to have easier access to the more recent commits.

Not possible to bypass http_proxy environment variable when using ruby 2.0

In Ruby 2.0+, you are required to explicitly pass nil for proxy address when initializing Net::HTTP.
(http://ruby-doc.org/stdlib-2.0.0/libdoc/net/http/rdoc/Net/HTTP.html#method-c-new)

When passing proxy = nil to Rsolr.connect, http is initalized with proxy read from ENV:

Net::HTTP.new uri.host, uri.port

This behaviour differs in 2.0 from 1.9.3 and eariler, where Rsolr would connect without proxy.

This is a problem for us since we must use the proxy configured in env for other requests, but can't use it for communicating with solr

No basic auth?

I have a solr instance that requires basic auth; I've been getting around this by using net/http basic_auth, but I would love it if there was some way for the rsolr gem to allow for basic auth on an rsolr request.

Cheers,
Kristopher

new rubygems release

Have you any plans to release new versions of rsolr? I'm waiting utf-8 query fixes in gem because Heroku couldn't use rsolr from git source due slug size limitation. So I use ugly monkey patches in initializers :(

Is support for SolrCloud on the roadmap?

We would like to start using SolrCloud, but we can't find a Ruby library that supports it. Are there any plans to integrate SolrCloud support into RSolr? Or is my best bet to use JRuby and SolrJ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.