Author: ehatcher
Date: Wed Aug 22 05:05:15 2007
New Revision: 568577

URL: http://svn.apache.org/viewvc?rev=568577&view=rev
Log:
Add preliminary support for SOLR-139, allowing updateable documents.  Added 
utility method to backslash escape strings suitable for QueryParser.  Bumped 
version number for another upcoming gem push.

Added:
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/modify_document.rb 
  (with props)
    
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/modify_document.rb   
(with props)
    lucene/solr/trunk/client/ruby/solr-ruby/test/unit/modify_document_test.rb   
(with props)
Modified:
    lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml
    lucene/solr/trunk/client/ruby/solr-ruby/Rakefile
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/connection.rb
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/standard.rb
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/util.rb
    lucene/solr/trunk/client/ruby/solr-ruby/test/unit/util_test.rb

Modified: lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml Wed Aug 22 05:05:15 2007
@@ -1,3 +1,11 @@
+- v0.0.5
+  release_date: 2007-08-??
+  changes:
+    - Added support for highlighter fragment size to Solr::Request::Standard
+    - Added support for MoreLikeThese to Solr::Request::Standard
+    - Added Solr::Request::ModifyDocument (requires SOLR-139 patch)
+    - Added Solr::Util.query_parser_escape()
+
 - v0.0.4
   release_date: 2007-08-16
   changes:

Modified: lucene/solr/trunk/client/ruby/solr-ruby/Rakefile
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/Rakefile?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/Rakefile (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/Rakefile Wed Aug 22 05:05:15 2007
@@ -29,7 +29,7 @@
 # 
 #    rake SOLR_CONSOLE=true
 
-SOLR_RUBY_VERSION = '0.0.4'
+SOLR_RUBY_VERSION = '0.0.5'
 
 require 'rubygems'
 require 'rake'

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/connection.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/connection.rb?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/connection.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/connection.rb Wed Aug 22 
05:05:15 2007
@@ -28,7 +28,7 @@
   #   conn = Solr::Connection.new('http://example.com:8080/solr', 
   #     :autocommit => :on)
 
-  def initialize(url, opts={})
+  def initialize(url="http://localhost:8983/solr";, opts={})
     @url = URI.parse(url)
     unless @url.kind_of? URI::HTTP
       raise "invalid http url: #{url}"

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb Wed Aug 22 
05:05:15 2007
@@ -12,6 +12,7 @@
 
 module Solr; module Request; end; end
 require 'solr/request/add_document'
+require 'solr/request/modify_document'
 require 'solr/request/base'
 require 'solr/request/commit'
 require 'solr/request/delete'

Added: 
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/modify_document.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/modify_document.rb?rev=568577&view=auto
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/modify_document.rb 
(added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/modify_document.rb 
Wed Aug 22 05:05:15 2007
@@ -0,0 +1,61 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'solr/xml'
+require 'solr/request/base'
+require 'solr/document'
+require 'solr/request/update'
+
+class Solr::Request::ModifyDocument < Solr::Request::Update
+
+  # Example: ModifyDocument.new(:id => 10, :overwrite => {:field_name => "new 
value"})
+  def initialize(update_data)
+    modes = []
+    @fields = {}
+    [:overwrite, :append, :distinct, :increment].each do |mode|
+      field_data = update_data[mode]
+      if field_data
+        field_data.each do |field_name, field_value|
+          modes << "#{field_name}:#{mode.to_s.upcase}"
+          @fields[field_name] = field_value
+        end
+        update_data.delete mode
+      end
+    end
+    @mode = modes.join(",")
+    @id = update_data  # should only be one key remaining
+  end
+
+  # returns the request as a string suitable for posting
+  def to_s
+    e = Solr::XML::Element.new 'add'
+    doc = Solr::XML::Element.new 'doc'
+    e.add_element doc
+    f = Solr::XML::Element.new 'field'
+    f.attributes['name'] = @id.keys[0].to_s
+    f.text = @id.values[0]
+    doc.add_element f
+    @fields.each do |key, value|
+      f = Solr::XML::Element.new 'field'
+      f.attributes['name'] = key.to_s
+      # TODO - what about boost?  - can it be updated too?
+      f.text = value
+      doc.add_element f
+    end
+    return e.to_s
+  end
+  
+  def handler
+    "[EMAIL PROTECTED]"
+  end
+  
+end

Propchange: 
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/modify_document.rb
------------------------------------------------------------------------------
    svn:executable = *

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb Wed Aug 22 
05:05:15 2007
@@ -16,6 +16,7 @@
 require 'solr/response/ruby'
 require 'solr/response/ping'
 require 'solr/response/add_document'
+require 'solr/response/modify_document'
 require 'solr/response/standard'
 require 'solr/response/dismax'
 require 'solr/response/commit'

Added: 
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/modify_document.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/modify_document.rb?rev=568577&view=auto
==============================================================================
--- 
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/modify_document.rb 
(added)
+++ 
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/modify_document.rb 
Wed Aug 22 05:05:15 2007
@@ -0,0 +1,17 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class Solr::Response::ModifyDocument < Solr::Response::Xml
+  def initialize(xml)
+    super
+  end
+end

Propchange: 
lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/modify_document.rb
------------------------------------------------------------------------------
    svn:executable = *

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/standard.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/standard.rb?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/standard.rb 
(original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/standard.rb Wed 
Aug 22 05:05:15 2007
@@ -36,6 +36,7 @@
     @response['maxScore']
   end
   
+  # TODO: consider the use of json.nl parameter
   def field_facets(field)
     facets = []
     values = @data['facet_counts']['facet_fields'][field]

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/util.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/util.rb?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/util.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/util.rb Wed Aug 22 
05:05:15 2007
@@ -25,4 +25,8 @@
     Hash[*a]
   end
   
+  def self.query_parser_escape(string)
+    # backslash prefix everything that isn't a word character
+    string.gsub(/(\W)/,'\\\\\1')
+  end
 end

Added: lucene/solr/trunk/client/ruby/solr-ruby/test/unit/modify_document_test.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/test/unit/modify_document_test.rb?rev=568577&view=auto
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/test/unit/modify_document_test.rb 
(added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/test/unit/modify_document_test.rb 
Wed Aug 22 05:05:15 2007
@@ -0,0 +1,25 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'test/unit'
+require 'solr'
+
+class ModifyDocumentTest < Test::Unit::TestCase
+
+  def test_update_formatting
+    request = Solr::Request::ModifyDocument.new(:id => 10, :overwrite => 
{:name => :value})
+    assert_equal :xml, request.response_format
+    assert_equal 'update?mode=name:OVERWRITE', request.handler
+    
+    assert_match(/<add>[\s]*<doc>[\s]*<field 
name=["']id['"]>10<\/field>[\s]*<field 
name=['"]name['"]>value<\/field>[\s]*<\/doc>[\s]*<\/add>/, request.to_s)
+  end
+end

Propchange: 
lucene/solr/trunk/client/ruby/solr-ruby/test/unit/modify_document_test.rb
------------------------------------------------------------------------------
    svn:executable = *

Modified: lucene/solr/trunk/client/ruby/solr-ruby/test/unit/util_test.rb
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/test/unit/util_test.rb?rev=568577&r1=568576&r2=568577&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/test/unit/util_test.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/test/unit/util_test.rb Wed Aug 22 
05:05:15 2007
@@ -14,9 +14,11 @@
 require 'test/unit'
 
 class UtilTest < Test::Unit::TestCase
-
   def test_paired_array_to_hash
     assert_equal({:key1 => :value1, :key2 => :value2}, 
Solr::Util.paired_array_to_hash([:key1, :value1, :key2, :value2]))
   end
 
+  def test_query_parser_escape
+    assert_equal %q(http\:\/\/lucene\.apache\.org\/solr), 
Solr::Util.query_parser_escape("http://lucene.apache.org/solr";)
+  end
 end


Reply via email to