mirror of https://github.com/apache/lucene.git
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.
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@568577 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d72ae657f1
commit
8c0599def1
|
@ -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:
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#
|
||||
# rake SOLR_CONSOLE=true
|
||||
|
||||
SOLR_RUBY_VERSION = '0.0.4'
|
||||
SOLR_RUBY_VERSION = '0.0.5'
|
||||
|
||||
require 'rubygems'
|
||||
require 'rake'
|
||||
|
|
|
@ -28,7 +28,7 @@ class Solr::Connection
|
|||
# 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}"
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
"update?mode=#{@mode}"
|
||||
end
|
||||
|
||||
end
|
|
@ -16,6 +16,7 @@ require 'solr/response/xml'
|
|||
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'
|
||||
|
|
|
@ -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
|
|
@ -36,6 +36,7 @@ class Solr::Response::Standard < Solr::Response::Ruby
|
|||
@response['maxScore']
|
||||
end
|
||||
|
||||
# TODO: consider the use of json.nl parameter
|
||||
def field_facets(field)
|
||||
facets = []
|
||||
values = @data['facet_counts']['facet_fields'][field]
|
||||
|
|
|
@ -25,4 +25,8 @@ class Solr::Util
|
|||
Hash[*a]
|
||||
end
|
||||
|
||||
def self.query_parser_escape(string)
|
||||
# backslash prefix everything that isn't a word character
|
||||
string.gsub(/(\W)/,'\\\\\1')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -14,9 +14,11 @@ require 'solr'
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue