Wednesday, October 22, 2008

DelSolr 0.0.2 Released - Added Support for Updates/Delete

A while ago I posted on the first version of delsolr (0.0.1) which provided support for querying solr and not much else :). We just released an update to delsolr (0.0.2). The major change is added support for updating/deleting documents. It's still fairly untested, so, standard disclaimer applies.
c = => 'solr', :port => 8983)

# updating one document...
doc =
doc.add_field('id', 'ABC-123')
doc.add_field('name', '8 Gig Shuffle')
doc.add_field('description', 'A crazy-tiny MP3 player')
c.update!(doc) # posts new document to solr

# updating a whole bunch and batching the post to solr
models = SomeModel.find(:all)
models.each do |model|
  doc =
  doc.add_field('description', model.description)
c.post_update! # post all the updates in one batch

c.commit! # post a commit to solr
I used a rails example, but delsolr is really intended for ruby and not necessarily rails. Acts_as_solr and the like might suit some better (but not us). This project came out of a piece of code we use internally to manage solr connections. My goal is to get delsolr to the point where we can replace our old implementation. It's not there yet, but it's getting closer. (It's slow going as this is largely done in our "free time".)

1 comment:

evindha said...

By using acts_as_solr we can do :

By using acts_as_ferret we can do :

How to search in any model by using DelSolr?

I have two models, User and Address
I want to search User which have value "amanda", so I run this :

c = => 'localhost', :port => 8982)
rsp = c.query('standard', :query => 'amanda')

And then I get 1 result.

How to search value "nevada" in Address model ?

If I run query like this :
rsp = c.query('standard', :query => 'amanda')
I have no results.

Please help me for this problem.

Thank you.