Solr
  1. Solr
  2. SOLR-826

For the solr-ruby-refactoring movement

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: clients - ruby - flare
    • Labels:
      None

      Description

      This is a patch to add a new directory to the solr-ruby-refactoring "branch". It's a very lightweight blob of code for connecting, selecting, updating and deleting using Ruby. It requires the URI and Net::HTTP libraries. No tests at the moment but I think the comments will do for now.

      1. experiments.patch
        4 kB
        Matt Mitchell
      2. experiments.2.patch
        3 kB
        Matt Mitchell
      3. experiments.3.patch
        12 kB
        Matt Mitchell
      4. experiments.4.patch
        12 kB
        Matt Mitchell

        Activity

        Hide
        Erik Hatcher added a comment -

        solr-ruby has been "retired" to <https://github.com/erikhatcher/solr-ruby-flare/tree/master/solr-ruby>. RSolr is Matt's API that most rubyists are using these days.

        Show
        Erik Hatcher added a comment - solr-ruby has been "retired" to < https://github.com/erikhatcher/solr-ruby-flare/tree/master/solr-ruby >. RSolr is Matt's API that most rubyists are using these days.
        Hide
        Matt Mitchell added a comment - - edited

        Added exception handling when querying or updating.

        • parses solr html response errors when using http connection

        Return a Solr::Response::* if :wt == :ruby
        Return a raw response (String) if :wt != :ruby
        Can set default_:wt in Solr::Server
        Can set :auto_commit in Solr::Server
        Added xml escaping to values and attributes

        Examples:

        connection = Solr::Connection::HTTP.new

        • if running under jRuby, could also do:
        • connection = Solr::Connection::Direct.new('/solr-home/path')

        solr = Solr::Server.new(connection, {:default_wt=>:ruby, :auto_commit=>true})

        r = solr.add :id=>1, :sku=>'L009'
        r.class == Solr::Response::Update
        puts r.query_time

        • raises exception (duplicate docs with same :id) - only works with HTTP connection
          r = solr.add :id=>1, :sku=>'L009'

        r = solr.query :q=>':'
        r.class == Solr::Response::Query

        • raises exception (invalid syntax)
          r = solr.query :q=>':'

        r = solr.query :q=>':', :wt=>:xml
        r.class == String
        h = Hpricot(r)

        r = solr.query :q=>':', :wt=>:json
        r.class == String
        j = JSON.parse(r)

        Main modules/classes:

        Solr
        Solr::XML < Xout (xml generator)
        Solr::Server
        Solr::Connection::HTTP
        Solr::Connection::Direct
        Solr::Connection::URLHelpers
        Solr::Response::Base
        Solr::Response::Query
        Solr::Response::Update

        Show
        Matt Mitchell added a comment - - edited Added exception handling when querying or updating. parses solr html response errors when using http connection Return a Solr::Response::* if :wt == :ruby Return a raw response (String) if :wt != :ruby Can set default_:wt in Solr::Server Can set :auto_commit in Solr::Server Added xml escaping to values and attributes Examples: connection = Solr::Connection::HTTP.new if running under jRuby, could also do: connection = Solr::Connection::Direct.new('/solr-home/path') solr = Solr::Server.new(connection, {:default_wt=>:ruby, :auto_commit=>true}) r = solr.add :id=>1, :sku=>'L009' r.class == Solr::Response::Update puts r.query_time raises exception (duplicate docs with same :id) - only works with HTTP connection r = solr.add :id=>1, :sku=>'L009' r = solr.query :q=>' : ' r.class == Solr::Response::Query raises exception (invalid syntax) r = solr.query :q=>':' r = solr.query :q=>' : ', :wt=>:xml r.class == String h = Hpricot(r) r = solr.query :q=>' : ', :wt=>:json r.class == String j = JSON.parse(r) Main modules/classes: Solr Solr::XML < Xout (xml generator) Solr::Server Solr::Connection::HTTP Solr::Connection::Direct Solr::Connection::URLHelpers Solr::Response::Base Solr::Response::Query Solr::Response::Update
        Hide
        Matt Mitchell added a comment -

        Here is a version that supports http (standard ruby) and jruby (direct connection) within the same interface. I'm trying my best to keep things as simple as possible and staying away from extra dependencies.

        I'm wondering, do we really need to support other response formats? If you decide to set the wt to xml, then returning the raw xml should be good enough right? What if someone wants to use Hpricot? What about REXML? If it's raw, then you could use whatever you'd like. It might be better to let people decide on how they'd like to handle alternate response formats? Thoughts?

        Show
        Matt Mitchell added a comment - Here is a version that supports http (standard ruby) and jruby (direct connection) within the same interface. I'm trying my best to keep things as simple as possible and staying away from extra dependencies. I'm wondering, do we really need to support other response formats? If you decide to set the wt to xml, then returning the raw xml should be good enough right? What if someone wants to use Hpricot? What about REXML? If it's raw, then you could use whatever you'd like. It might be better to let people decide on how they'd like to handle alternate response formats? Thoughts?
        Hide
        Matt Mitchell added a comment -

        Just to make it clear, the comment above was just me thinking (no code here to support it)... We can get to the fancy higher level API stuff with add-on modules down the road.

        Show
        Matt Mitchell added a comment - Just to make it clear, the comment above was just me thinking (no code here to support it)... We can get to the fancy higher level API stuff with add-on modules down the road.
        Hide
        Matt Mitchell added a comment - - edited

        Thoughts on an interface like this? Similar to what's there now I suppose, except for the add part.

        # add a single doc
        solr.add :product_name=>'Waffle Pro II'
        
        # add a single doc with doc options (most common use probably)
        solr.add {:product_name=>'Waffle Semi-Pro'}, :boost=>1.5
        
        # add multiple docs, with add options, doc options and field options
        
        solr.add(:allowDups=>false, :commitWithin=>10) do |add|
          add.doc :product_name=>'Waffle Pro II'
          add.doc {:product_name=>'Waffle Semi-Pro'}, :boost=>1.5
          add.doc(:boost=>10) do |doc|
            doc.field :product_name, 'Waffle Basic'
            doc.field :description, 'The fastest way to get from here to there', :boost=>10.0
          end
        end
        
        # delete by id
        solr.delete_by_id 1
        
        # delete multiples by id
        solr.delete_by_id 1, 2, 3, 4
        
        # delete by query
        solr.delete_by_query 'quantity:0'
        
        # delete multiples by query
        solr.delete_by_query 'quantity:0', 'available:false'
        Show
        Matt Mitchell added a comment - - edited Thoughts on an interface like this? Similar to what's there now I suppose, except for the add part. # add a single doc solr.add :product_name=>'Waffle Pro II' # add a single doc with doc options (most common use probably) solr.add {:product_name=>'Waffle Semi-Pro'}, :boost=>1.5 # add multiple docs, with add options, doc options and field options solr.add(:allowDups=> false , :commitWithin=>10) do |add| add.doc :product_name=>'Waffle Pro II' add.doc {:product_name=>'Waffle Semi-Pro'}, :boost=>1.5 add.doc(:boost=>10) do |doc| doc.field :product_name, 'Waffle Basic' doc.field :description, 'The fastest way to get from here to there', :boost=>10.0 end end # delete by id solr.delete_by_id 1 # delete multiples by id solr.delete_by_id 1, 2, 3, 4 # delete by query solr.delete_by_query 'quantity:0' # delete multiples by query solr.delete_by_query 'quantity:0', 'available: false '
        Hide
        Matt Mitchell added a comment -

        This is even more stripped down. A basic connection with get/post methods. Keeping it simple like this would provide the possibility of mixing in different modules for higher-level methods like add, delete_by_id etc..

        Show
        Matt Mitchell added a comment - This is even more stripped down. A basic connection with get/post methods. Keeping it simple like this would provide the possibility of mixing in different modules for higher-level methods like add, delete_by_id etc..

          People

          • Assignee:
            Unassigned
            Reporter:
            Matt Mitchell
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development