SOLR-147: Add DisMax support

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@505105 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-02-09 00:43:32 +00:00
parent 33d170b6bc
commit d0b674a2a8
5 changed files with 46 additions and 6 deletions

View File

@ -77,11 +77,11 @@ class Solr::Connection
def query(query, options={}, &action)
# TODO: Shouldn't this return an exception if the Solr status is not ok? (rather than true/false).
options[:query] = query
request = Solr::Request::Standard.new(options)
response = send(request)
return response unless action
response.each {|hit| action.call(hit)}
create_and_send_query(Solr::Request::Standard, options.update(:query => query), &action)
end
def search(query, options={}, &action)
create_and_send_query(Solr::Request::Dismax, options.update(:query => query), &action)
end
# sends a commit message to the server
@ -150,4 +150,13 @@ class Solr::Connection
end
private
def create_and_send_query(klass, options = {}, &action)
request = klass.new(options)
response = send(request)
return response unless action
response.each {|hit| action.call(hit)}
end
end

View File

@ -18,5 +18,6 @@ require 'solr/request/delete'
require 'solr/request/ping'
require 'solr/request/select'
require 'solr/request/standard'
require 'solr/request/dismax'
require 'solr/request/update'
require 'solr/request/index_info'

View File

@ -17,6 +17,7 @@ require 'solr/response/ruby'
require 'solr/response/ping'
require 'solr/response/add_document'
require 'solr/response/standard'
require 'solr/response/dismax'
require 'solr/response/commit'
require 'solr/response/delete'
require 'solr/response/index_info'

View File

@ -237,6 +237,30 @@
</lst>
</requestHandler>
<!-- DisMaxRequestHandler allows easy searching across multiple fields
for simple user-entered phrases.
see http://wiki.apache.org/solr/DisMaxRequestHandler
-->
<requestHandler name="dismax" class="solr.DisMaxRequestHandler" >
<lst name="defaults">
<str name="echoParams">explicit</str>
<float name="tie">0.01</float>
<str name="qf">
text^1.9
</str>
<str name="pf">
text^1.9
</str>
<str name="fl">
id, text
</str>
<str name="mm">
2&lt;-1 5&lt;-2 6&lt;90%
</str>
<int name="ps">100</int> -->
</lst>
</requestHandler>
<!-- queryResponseWriter plugins... query responses will be written using the
writer specified by the 'wt' request parameter matching the name of a registered
writer.

View File

@ -42,6 +42,11 @@ class ServerTest < Test::Unit::TestCase
assert_equal 1, response.total_hits
assert_equal '123456', response.hits[0]['id']
# look for it via dismax
response = @connection.search('Borges')
assert_equal 1, response.total_hits
assert_equal '123456', response.hits[0]['id']
# delete it
@connection.delete(123456)