• Products
    • Overview
    • LucidWorks Search Platform
      • Features and Benefits
      • Technical Overview
      • Only with LucidWorks
      • LucidWorks and Solr
      • White Papers
      • LucidWorks Enterprise
      • LucidWorks Cloud
    • Certified Distributions
      • Certified Solr
      • Certified Lucene
    • Apache Releases
      • Apache Solr
      • Apache Lucene
  • Support & Services
    • Overview
    • Support
    • Training
    • Solr/Lucene Certification
    • ExpertLink Advisory
    • Consulting
    • Partners
    • Subscriptions
  • Why Lucid?
    • Why Lucid?
    • Technology
    • Technical Leadership
    • Who uses Lucene/Solr?
      • What customers are saying
    • Case Studies
    • Whitepapers
    • Demos
    • Webinars
  • Blog
  • DevZone
    • DevZone Overview
    • Forums (LWE)
    • Videos & Podcasts
      • How To's
      • Screencasts
      • Podcasts
      • Conference Videos
    • Technical Articles
      • Whitepapers
    • Reference Materials
      • Documentation
      • Solr Reference Guide
      • Solr & LucidWorks Matrix
      • Tutorials
    • Events
      • Conferences
      • Meet Ups
    • Code & Test
  • Downloads
  • About Us
    • Management
    • Careers
    • News
      • Media Coverage
      • Press Releases
    • Contact Us
Sign Up or Log In
Home . Blog

February 17, 2009

acts_as_solr with rich document indexing

Posted by Erik Hatcher

A hearty thanks to the Central Virginia Ruby Enthusiasts’ Group, who invited me to speak on Solr+Ruby giving me a good reason to delve deeply back into solr-ruby and acts_as_solr.

Let’s start a Rails project from scratch to illustrate how simple it is to get up and running with acts_as_solr. The example is, indeed, a fairly real-world’ish type of need. We’re going to index resumes, which could be in standard rich document formats such as PDF, Word, HTML, or plain text.

rails resume
cd resume
script/generate scaffold resume first_name:string last_name:string file_name:string
rake db:migrate

Thanks to the magic that is Rails, we now have a working application that allows standard CRUD operations on a resumes table in a relational database. (not discussed further here, but start script/server and to navigate to the usual http://localhost:3000/resumes. We’re going to stick closer to the metal and use script/console for direct ActiveRecord and Solr API tinkering)

Next we add the acts_as_solr plugin to our application:

script/plugin install git://github.com/mattmatt/acts_as_solr.git

A note about the acts_as_solr codebase: it all started with an innocent hack that I posted to the solr-user list. It got picked up [editor 3/18/09: respectfully added a special mention of Thiago Jackiw] by Thiago and he turned it  into a serious general purpose ActiveRecord modeling plugin hosted at RubyForge, and now exists as numerous git repository forks. The currently best maintained version is Mathias Meyer’s branch.

And we start Solr:

rake solr:start

We now add Solr to the lifecycle of the Resume model, such that when a Resume is added or updated in the database it also gets indexed into Solr, and deleted from Solr when it is removed from the database. It really couldn’t be any easier:

class Resume < ActiveRecord::Base
  acts_as_solr
end

Plugging in acts_as_solr provides not only the lifecycle hooks to keep the database and Solr in sync, it also provides additional finder methods. Here’s an example of using Resume#find_by_solr:

$ script/console
>> Resume.create(:first_name=>;'Joe', :last_name=>'Programmer')
>> Resume.find_by_solr("program*")
=> <#1.0460204, :query_time=>0, :total=>1, :docs=>[#<Resume id: 4, first_name: "Joe", last_name: "Programmer", file_name: nil, created_at: "2009-02-13 23:15:29", updated_at: "2009-02-13 23:15:29">]}>

The “program*” query matches any words indexed that begin with “program”. Note that the result from find_by_solr is an ActsAsSolr::SearchResults instance. This wrapper provides the docs that normally are returned from ActiveRecord finder methods in addition to other Solr information, including the query_time and total number of documents matched. The order of the docs array defaults to descending score (a measure of relevancy to a query).

So far so good – we’ve got a Rails application with an ActiveRecord model tied to acts_as_solr. Now comes the trickier part of indexing the resume text.

Solr Cell
A content extraction library (aka Solr Cell) was added in Solr 1.4. However, at the time of writing acts_as_solr embeds Solr 1.3. So we need to do a little hacking to bring in a newer version of Solr with the Solr Cell dependencies and configuration. In the future, it is likely acts_as_solr will ship with Solr Cell built-in, so be sure to check your version.

First, stop Solr:

rake solr:stop

Grab a nightly build of Solr from http://people.apache.org/builds/lucene/solr/nightly/. Unarchive the distribution, and copy over the lib directory containing the Solr Cell plugin and dependencies, and also replace solr.war (the entire Solr web application).

cp -R apache-solr-nightly/example/solr/lib resume/vendor/plugins/acts_as_solr/solr/solr/
cp apache-solr-nightly/example/webapps/solr.war resume/vendor/plugins/acts_as_solr/solr/webapps/solr.war

And now add the Solr Cell request handler to vendor/plugins/acts_as_solr/solr/solr/conf/solrconfig.xml (add it anywhere as sibling to the other request handlers defined):

And enable remote streaming by setting enableRemoteStreaming=”true” on the requestParsers element.

Enabling remote streaming comes with a stern warning “Make sure your system has some authentication before enabling remote streaming!”. Our best advice is to firewall Solr such that only the application server, or in this example simply localhost itself, can make requests to Solr. Having remote streaming enabled allows some request handlers, if configured, to pull content from a URL or from a local file path. This isn’t necessarily a bad thing, but restricting who or where requests can be made to Solr is a wise production deployment consideration. Even with remote streaming disabled, general /update is accessible and documents can be added or deleted easily. So do take this as a production deployment concern to address in your network architecture.

What this now gives us is the ability to index rich document content with simple requests to Solr. Thanks to Solr’s content streaming flexibility, Solr can get the file content from a local file path, a remotely accessible URL, or through the file actually being POSTed in the request. In this exercise, we’re going to send Solr a local file path, which assumes the Solr and Ruby ActiveRecord application tier can see the same path. Here’s an example of the kind of lightweight request it takes to index a PDF file:

curl "http://localhost:8982/solr/update/extract?stream.file=/path/to/ErikHatcherResume.pd&ext.idx.attr=false&ext.def.fl=text_t&ext.ignore.und.fl=true&ext.map.title=title_t&ext.literal.id=1&wt=ruby"

That’s some ugly parameters, but thankfully the Solr Cell wiki page spells them out in detail. The Solr request in prose – the local /path/to/ErikHatcherResume.pdf is sent to Solr, Solr reads the contents of that file, the text is extracted into the text_t field, undefined fields are ignored, general attributes extracted are ignored, but the title field is mapped to the title_t field, and the id field is mapped literally to the value of 1. The general purpose acts_as_solr schema has a convenient *_t field mapping for bringing in both the text content and metadata attributes as needed and all *_t fields are internally copied to a single searchable “text” field.

The solr-ruby library, at the time of this writing, does not have built-in support for Solr Cell style requests, though it easily allows custom request types to be used. Here’s our solr_cell_request.rb:

class SolrCellRequest < Solr::Request::Select
  def initialize(doc,file_name)
    params = {
      'ext.idx.attr' => false,        # don't index any attributes, unless explicitly mapped
      'ext.def.fl' => 'text_t',        # all text extracted goes to text_t (since it is a stored field, for highlighting)
      'ext.ignore.und.fl' => true,      # ignore all undefined fields
      'ext.map.title' => 'title_t',
      'ext.resource.name' => file_name, # TIKA-154 workaround
      'stream.file' => file_name,
    }
    doc.each do |f|
      params["ext.literal.#{f.name}"] = f.value
      if f.boost
        params["ext.boost.#{f.name}"] = f.boost
      end
    end
    super(nil,params)
  end
 
  def handler
    'update/extract'
  end
end
 
class SolrCellResponse < Solr::Response::Ruby
end

During the development SolrCellRequest, I noticed plain text (surprisingly!) files were not indexing. I asked about this and quickly received an explanation. This will be resolved when a newer version of Tika, including TIKA-154, is brought into Solr. In the meantime, setting ext.resource.name solves the issue.

The doc passed into the SolrCellRequest constructor is a Solr::Document. We’ve jumped ahead, knowing that we’ll be able to easily override an acts_as_solr method where the ActiveRecord is available as a Solr::Document. [note that solr-ruby does have the requirement that there be a parallel *Response class to the *Request. This is why the dummy SolrCellResponse is necessary]

script/console is still our friend, let’s give it a try using pure solr-ruby API:

$ script/console
Loading development environment (Rails 2.2.2)
>> solr = Solr::Connection.new("http://localhost:8982/solr")
>> req = SolrCellRequest.new(Solr::Document.new(:id=>1), '/path/to/ErikHatcherResume.pdf')
>> solr.send(req)
>> solr.commit

Checkpoint – we’ve now got Ruby able to index rich files into Solr by a very simple API. What’s left? We have to tie this indexing into the ActiveRecord lifecycle exposed by acts_as_solr. There’s a nice and easy method to override on a per-acts_as_solr-model basis to change how the indexing request to Solr works. It looks like this (in acts_as_solr’s commons_methods.rb):

    def solr_add(add_xml)   # note, it is actually a Solr::Document passed in, not XML
      ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml))
    end

We’ll override that in our Resume model:

class Resume < ActiveRecord::Base
  acts_as_solr
 
  def solr_add(doc)
    # puts doc.to_xml.to_s # handy view of the Solr doc acts_as_solr builds
    if file_name
      ActsAsSolr::Post.execute(SolrCellRequest.new(doc, file_name))
    else
      ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(doc))
    end
  end
end

And now the grand finale, the code us Rubyists love to see, that one elegant line of code:

>> Resume.create(:first_name => "Erik", :last_name=&gt;"Hatcher", :file_name=>"/path/to/ErikHatcherResume.pdf")

And a quick test that shows it works (“java” is in my resume):

>> Resume.find_by_solr("java")
=> <#1, :total=>1, :docs=>[#<Resume id: 6, first_name: "Erik", last_name: "Hatcher", file_name: "/path/to/ErikHatcherResume.pdf", created_at: "2009-02-17 22:33:16", updated_at: "2009-02-17 22:33:16">]}>

See also Sami Siren’s Content Extraction with Tika article.

We encourage you to provide comments and feedback to us on this entry. Particularly I’m interested in hearing from Solr-using Rubyists out there and what challenges you’ve faced in using Solr and how we can help fix bugs or educate further.

  • Share this:
  • Email
  • Facebook
  • Digg
  • Share
  • Print
  • Reddit
  • StumbleUpon

Category: Ruby, Solr

Tags: acts_as_solr, Ruby

23 Responses to “acts_as_solr with rich document indexing”

  1. Very interesting article, thank you for posting this Erik.

    My requirements were a bit different. I needed to submit the document data along with the rest of the information (rather than sending a file name for streaming).

    I used ‘stream.body’ in params (instead of ‘stream.file’) and overwrite to_s

    Here is the code if someone is interested (the modifications are trivial):

    class SolrCellRequest  false,        # don't index any attributes, unless explicitly mapped
          'ext.def.fl' =&gt; 'body_t',        # all text extracted goes to text_t (since it is a stored field, for highlighting)
          'ext.ignore.und.fl' =&gt; true,      # ignore all undefined fields
          'ext.map.title' =&gt; 'title_t',
    			'stream.body' =&gt; doc["body_t"]
        }
     
        doc.each do |f|
     
    				params["ext.literal.#{f.name}"] = f.value
    				if f.boost
    					params["ext.boost.#{f.name}"] = f.boost
    				end
     
        end
     
    		super(nil,params)
     
      end
     
      def handler
        'update/extract'
      end
     
    	def to_s
        raw_params = self.to_hash
     
        http_params = []
        raw_params.each do |key,value|
    			 http_params &lt;&lt; "#{key}=#{ERB::Util::url_encode(value)}" unless value.nil?
        end
     
        http_params.join("&amp;")
      end
     
     
     
    end
     
    class SolrCellResponse &lt; Solr::Response::Ruby
    end

    March 7, 2009 13:19 — Federico

  2. I’m attempting at using Solr as a replacement for Google CSE for our site. One key element is being able to index rich documents such as PDFs and DOCs. I was running through your tutorial and came across the below section.

    “And now add the Solr Cell request handler to vendor/plugins/acts_as_solr/solr/solr/conf/solrconfig.xml (add it anywhere as sibling to the other request handlers defined):”

    I wasn’t quite sure what I was supposed to do. Your help would be very much appreciated.

    March 20, 2009 12:42 — Jared Fine

  3. Jared –

    Good question. The Solr build that is used in this article contains the ExtractingRequestHandler mapped in the example solrconfig.xml. In order to use it, it needs to be declared in the solrconfig.xml that you’re using with acts_as_solr.

    Place this in your solrconfig.xml:

    <requestHandler name="/update/extract" class="org.apache.solr.handler.extraction.ExtractingRequestHandler"/>

    March 30, 2009 10:08 — Erik Hatcher

  4. Hi Erik,

    I am having problem following Recipe 27 of the Advanced Rails Recipes book. I tried to follow the steps you wrote to see if I can drill down the search results using facets.

    Initially solr and solr-ruby appeared to work fine. I ran import_books.rb script successfully and was able to get a solr connection on my irb session. The below statements worked fine too.

    solr = Solr::Connection.new(‘http://127.0.0.1:8983/solr‘)

    response = solr.query(‘pragmatic’, :facets => {:fields => ['pubisher_facet'], :mincount =>1}) docs = response.hits

    But when I ran
    response.facet_fields(‘publisher_facet’)

    I got the below error

    irb(main):013:0> response.field_facets(‘publisher_facet’) NoMethodError: undefined method `size’ for nil:NilClass from C:/Ruby/lib/ruby/gems/1.8/gems/solr-ruby-0.0.7/lib/solr/util.rb:17:in `paired_array_each’ from C:/Ruby/lib/ruby/gems/1.8/gems/solr-ruby-0.0.7/lib/solr/response/standard.rb:43:in `field_facets’ from (irb):13

    I am using solr 1.3, Ruby 1.8.6 on Windows Vista, solr-ruby 0.0.7.

    Please advise if the recipe can sill be used with out changes on solr 1.3 and solr-ruby 0.0.7?

    Thank you.

    Below are installed gems on my pc.

    C:\Users\thanh>ruby -v
    ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

    C:\Users\thanh>gem -v
    1.3.1

    C:\Users\thanh>gem list

    *** LOCAL GEMS ***

    actionmailer (2.3.2)
    actionpack (2.3.2)
    activerecord (2.3.2)
    activeresource (2.3.2)
    activesupport (2.3.2)
    capistrano (2.5.5)
    cgi_multipart_eof_fix (2.5.0)
    fxri (0.3.6)
    fxruby (1.6.16)
    gem_plugin (0.2.3)
    highline (1.5.0)
    hpricot (0.6.164)
    log4r (1.0.5)
    mongrel (1.1.5)
    mongrel_cluster (1.0.5)
    net-scp (1.0.2)
    net-sftp (2.0.2)
    net-ssh (2.0.11)
    net-ssh-gateway (1.0.1)
    ptools (1.1.6)
    rails (2.3.2)
    rake (0.8.4, 0.8.1)
    ruby-opengl (0.60.0)
    solr-ruby (0.0.7)
    test-unit (2.0.1)
    win32-api (1.2.1, 1.2.0)
    win32-clipboard (0.4.4)
    win32-dir (0.3.2)
    win32-eventlog (0.5.0)
    win32-file (0.5.5)
    win32-file-stat (1.3.1)
    win32-process (0.5.9)
    win32-sapi (0.1.4)
    win32-sound (0.4.1)
    windows-api (0.2.4)
    windows-pr (0.9.3)

    April 10, 2009 17:33 — Thanh Doan

  5. Thanh – it’s field_facets.

    I replied to your solr-user post also, see here: http://www.lucidimagination.com/search/document/6dad03abade708a2/evaluating_solr_and_ruby_solr

    April 12, 2009 06:21 — Erik Hatcher

  6. Thanks Erik.

    April 26, 2009 23:00 — Thanh Doan

  7. I may be just being something of an idiot, but I’m having trouble that I don’t see any questions about…

    I followed the guide above, adding the line:

    
    

    above. However, I get the following error:

    org.apache.solr.common.SolrException: Error loading class ‘org.apache.solr.handler.extraction.ExtractingRequestHandler’

    I’ve checked that I have the files in the required path (app/vendor/plugins/acts_as_solr/solr/solr) as listed above, but it doesn’t pick it up. on a whim, I put them in (app/vendor/plugins/acts_as_solr/solr/lib) with the other jar files, and it stops throwing that error, but throws this error now:

    java.lang.NoClassDefFoundError: org/apache/solr/util/plugin/SolrCoreAware

    which seems even more obtuse to me. Apparently SolrCoreAware is an interface for allowing plugins to be informed about the SolrCore/ResourceLoader, but I haven’t ever looked at the Solr java source enough to figure that out…

    anyone have any thoughts on what I may be doing wrong?

    Thanks!
    Pete

    April 27, 2009 12:10 — Pete

  8. Pete – what version of Solr are you using? My hunch is that you didn’t replace the solr.war file properly, as indicated by the copy problem you experienced with the libraries also.

    Double check that you ran the cp (copy) commands as stated above.

    May 5, 2009 08:41 — Erik Hatcher

  9. Hi,

    if i add an Solr::Document to the index with solr_add()
    i get the following error:

    solr_cell_request.rb:13:in `initialize’: undefined method `each’ for # (NoMethodError)

    —
    solr_cell_request.rb:

    13: doc.each do |f|
    14: params["ext.literal.#{f.name}"] = f.value
    15: if f.boost
    16: params["ext.boost.#{f.name}"] = f.boost
    17: end
    18: end
    19: super(nil,params)
    20: end

    anyone have an idea on what I doing wrong?

    July 22, 2009 04:04 — Daniel

  10. I get the same errors as Phil. I’m pretty darn sure I followed the instructions perfectly (two or 3 times). I also tried to “ant example” just in case that was the issue. Nope.

    SEVERE: Could not start SOLR. Check solr/home property
    java.lang.NoClassDefFoundError: org/apache/solr/util/plugin/SolrCoreAware
    at java.lang.ClassLoader.defineClass1(Native Method)

    …./*snip*/….

    Thank you.

    August 7, 2009 12:53 — Kevin Reagan

  11. I am just getting started with Ruby and Solr (v 1.3 — it is all that is available at the customer site). So, my question is, querying via acts_as_solr returns the full doc definition I expect for my model. But, when I query solr directly (http://localhost/solr/select?q=blah…, I only get the id and the pk_i.

    I have been mucking about in the schema and solfconfig xml files to no avail.

    Is it possible to have solr return the full doc definition as in acts_as_solr?

    Sorry if this is a silly question, I just can’t seem to get any traction on this issue.

    Cheers
    Mike

    September 29, 2009 02:56 — Mike Boyle

  12. Hi,
    I got this error
    D:\resume>rake solr:start
    (in D:/resume)
    rake aborted!
    fork() function is unimplemented on this machine
    (See full trace by running task with –trace)

    i am using ruby on rails version bellow.
    ruby 1.8.6
    rails 2.3.4

    my gems list

    *** LOCAL GEMS ***

    abstract (1.0.0)
    actionmailer (2.3.4, 2.3.3, 2.3.2, 2.2.2, 2.1.1, 2.1.0, 2.0.2, 1.3.3)
    actionpack (2.3.4, 2.3.3, 2.3.2, 2.2.2, 2.1.1, 2.1.0, 2.0.2, 1.13.6, 1.13.3)
    actionwebservice (1.2.6, 1.2.3)
    activemerchant (1.4.2)
    activerecord (2.3.4, 2.3.3, 2.3.2, 2.2.2, 2.1.1, 2.1.0, 2.0.2, 1.15.6, 1.15.3)
    activerecord-tableless (0.1.0)
    activeresource (2.3.4, 2.3.3, 2.3.2, 2.2.2, 2.1.1, 2.1.0, 2.0.2)
    activesupport (2.3.4, 2.3.3, 2.3.2, 2.2.2, 2.1.1, 2.1.0, 2.0.2, 1.4.4, 1.4.2)
    acts_as_ferret (0.4.4, 0.4.3)
    acts_as_reportable (1.1.1, 1.0.1)
    addressable (2.1.0, 2.0.1, 2.0.0)
    archive-tar-minitar (0.5.2, 0.5.1)
    arrayfields (4.7.4, 4.6.0)
    authlogic (2.1.2)
    builder (2.1.2)
    cached_model (1.3.1)
    calendar_date_select (1.15)
    capistrano (2.5.9, 2.5.3, 2.5.0, 2.1.0)
    cgi_multipart_eof_fix (2.5.0)
    chriseppstein-compass (0.6.15)
    chronic (0.2.3)
    cmdparse (2.0.2)
    color (1.4.0)
    columnize (0.3.1, 0.2, 0.1)
    commonwatir (1.6.2)
    daemons (1.0.10)
    data_objects (0.10.0, 0.9.9, 0.9.8)
    diff-lcs (1.1.2)
    dm-core (0.10.1, 0.9.8, 0.9.7)
    erubis (2.6.5, 2.6.2)
    eventmachine (0.12.8, 0.12.0)
    extlib (0.9.13, 0.9.9, 0.9.8)
    facets (2.7.0, 1.4.5)
    fastercsv (1.5.0, 1.4.0, 1.2.3)
    fattr (2.1.0, 1.0.3)
    feed-normalizer (1.5.1)
    ferret (0.11.5)
    firewatir (1.6.2)
    flexmock (0.8.6, 0.8.2)
    fxri (0.3.7, 0.3.6)
    fxruby (1.6.19, 1.6.12)
    gem_plugin (0.2.3)
    gettext (2.0.4, 1.93.0, 1.90.0)
    git (1.2.5, 1.0.5)
    git-rails (0.2.1)
    haml (2.2.9, 2.0.4)
    haml-edge (2.3.65)
    highline (1.5.1, 1.4.0)
    hoe (2.3.3, 1.8.0, 1.5.0, 1.4.0)
    hpricot (0.8.1, 0.6)
    javan-whenever (0.3.7)
    json_pure (1.1.9, 1.1.3)
    libxml-ruby (1.1.3)
    linecache (0.43)
    liquid (2.0.0, 1.9.0)
    locale (2.0.4)
    log4r (1.1.2, 1.0.5)
    mailfactory (1.4.0)
    main (4.0.0, 2.8.2)
    mechanize (0.9.3, 0.8.5)
    memcache-client (1.7.5, 1.5.0)
    merb-action-args (1.0.12, 1.0.3)
    merb-assets (1.0.12, 1.0.3)
    merb-auth (1.0.12, 1.0.3)

    November 9, 2009 01:35 — vijay

  13. I got the nil error too.. but I’m not using facets.. :S
    –rake –trace solr:start
    (in /home/diego/rptest)
    ** Invoke solr:start (first_time)
    ** Execute solr:start
    rake aborted!
    undefined method `closed?’ for nil:NilClass
    /usr/lib64/ruby/1.8/net/http.rb:1060:in `request’
    /usr/lib64/ruby/1.8/net/http.rb:962:in `request_head’
    /home/diego/rptest/vendor/plugins/acts_as_solr/lib/tasks/solr.rake:13
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain’
    /usr/lib64/ruby/1.8/monitor.rb:242:in `synchronize’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run’
    /usr/lib64/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
    /usr/bin/rake:19:in `load’
    /usr/bin/rake:19
    –

    might it be because of the server/port conflict?
    thx :)

    January 29, 2010 07:09 — adedip

  14. @Vijay:

    You seem to be running Rails on windows. Fork is not implemented. Hence heres a hack for your problem:

    1. Open \resume\vendor\plugins\acts_as_solr\tasks\solr.rake
    2. Add this before the def env_array_to_constants(env):

    desc ‘Starts Solr. on windows . Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.’
    task :start_win do
    require “#{File.dirname(__FILE__)}/../../config/solr_environment.rb”
    begin
    n = Net::HTTP.new(‘localhost’, SOLR_PORT)
    n.request_head(‘/’).value

    rescue Net::HTTPServerException #responding
    puts “Port #{SOLR_PORT} in use” and return

    rescue Errno::ECONNREFUSED #not responding
    Dir.chdir(SOLR_PATH) do
    exec “java -Dsolr.data.dir=solr/data/#{ENV['RAILS_ENV']} -Djetty.port=#{SOLR_PORT} -jar start.jar”
    sleep(5)
    puts “#{ENV['RAILS_ENV']} Solr started sucessfuly on #{SOLR_PORT}, pid: #{pid}.”
    end
    end
    end

    3. Make sure u run rake solr:start_win
    4. Cheers

    Source: http://webonrails.com/2007/09/13/acts_as_solr-starting-solr-server-on-windows/comment-page-1/#comment-1292

    February 7, 2010 08:54 — Shripad K

  15. I’m having trouble with one of the steps above:

    p -R apache-solr-nightly/example/solr/lib resume/vendor/plugins/acts_as_solr/solr/solr/

    The problem is, the directory doesn’t exist: there is no /example/solr/lib directory in the nightly build. When I grab a build from the link above, and look under apache-solr-1.5-dev/example/solr there is a /bin /conf and /data directory, but no lib

    Also, acts_as_solr/solr/solr doesn’t contain a lib directory either.

    Which files should appear in the lib directory in the nightly build? Am I replacing files with the same name in the plugin, or adding files which aren’t there already?

    Any help would be much appreciated. This tutorial is exactly what I’ve been looking for, and I can’t quite get it to work.

    -

    March 10, 2010 16:36 — Brad T

  16. @adedip That “nil.close?” error is actually a ruby bug. Update your 1.8.7 ruby to the latest patchlevel!!

    June 29, 2010 08:36 — darius

  17. I’m having this same problem with rake solr:start

    undefined method `closed?’ for nil:NilClass

    the ruby version:
    ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]

    July 15, 2010 13:41 — Lucas Renan

  18. How can I use act_as_solr to index the cassandra database.
    thanks in advace

    January 9, 2011 02:29 — Naveen

  19. Hi,

    Nice document i need to search document content so i need to use this plugin, is this available in rails 3.

    March 22, 2011 01:16 — sunny

  20. hi,I need to do document search (.pdf,.doc,.docx,.ppt,.xls ….) & i found this post it’s very usefull but i am running with some issues and it’s very difficult to figure out.Do you have any idea how can i do document content search in rails 3 & using acts_as_solr

    June 10, 2011 00:24 — sunny

  21. Hi,
    I’m running on WindowsOS, trying to follow through this turorial. But when I run the Resume.create(:first_name=>’Joe’, :last_name=>’Programmer’), – received an error, ‘TypeError: Cannot modify SafeBuffer I nplace”. Any advice on that?

    Thanks.

    September 7, 2011 17:18 — Em

  22. where is solr_cell_request.rb placed/found?

    September 8, 2011 00:04 — Em

  23. hi,
    i”m running on WindowsOS, but when i tried the Resume.create command on console, i receive an error: Cannot modify SafeBuffer in place.

    and i cant enter the solr admin when i copy the solr.war over.

    any help?

    September 8, 2011 02:43 — emilie

Leave a Reply

Go to Blog Front Page

  • Recent Posts

    • Lucene Revolution 2012 – Call for Participation now open!
    • SolrCloud is Coming (and looking to mix in even more ‘NoSQL’)
    • Our Solr Reference Guide updated for v3.5
    • Enhancing Discovery with Solr and Mahout – session slides now available!
    • Solr and LucidWorks feature matrix available
    • LucidWorks Enterprise latest version 2.0.1 released!
    • Why Not AND, OR, And NOT?
    • Options to tune document’s relevance in Solr
    • Dallas JavaMUG December 14th 2011
    • Apache Mahout user meeting – session slides and videos are now available!
  • Archives

    • January 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • August 2011
  • Tags

    acts_as_solr apache Apache Mahout best practices chump code4lib dismax drupal enterprise search Erik Hatcher field collapsing function query Grant Ingersoll hoss image isfdb local params Lucene lucene revolution LucidGaze lucid imagination Mahout Marc Krellenstein Mark Miller nested queries nutch Open Source Open Source Search qparser query parser queryparser Rails release result grouping Richmond Ruby schema design sint Solr solr 3.1 solr 4.0 solr cloud sortable Tika VA
  • Contact Us
  • About Lucid Imagination
  • Help & Support
  • Training
  • Privacy Policy
  • Legal Terms of Use
  • Copyrights and Disclaimers
  • Log in

Apache Solr, Solr, Apache Lucene, Lucene and their logos are trademarks of the Apache Software Foundation.

© 2011 Lucid Imagination. All Right reserved.

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.