mirror of https://github.com/apache/lucene.git
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:
parent
33d170b6bc
commit
d0b674a2a8
|
@ -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
|
||||
|
@ -149,5 +149,14 @@ class Solr::Connection
|
|||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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'
|
|
@ -236,6 +236,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<-1 5<-2 6<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
|
||||
|
|
|
@ -41,6 +41,11 @@ class ServerTest < Test::Unit::TestCase
|
|||
response = @connection.query('Borges')
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue