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)
|
def query(query, options={}, &action)
|
||||||
# TODO: Shouldn't this return an exception if the Solr status is not ok? (rather than true/false).
|
# TODO: Shouldn't this return an exception if the Solr status is not ok? (rather than true/false).
|
||||||
options[:query] = query
|
create_and_send_query(Solr::Request::Standard, options.update(:query => query), &action)
|
||||||
request = Solr::Request::Standard.new(options)
|
end
|
||||||
response = send(request)
|
|
||||||
return response unless action
|
def search(query, options={}, &action)
|
||||||
response.each {|hit| action.call(hit)}
|
create_and_send_query(Solr::Request::Dismax, options.update(:query => query), &action)
|
||||||
end
|
end
|
||||||
|
|
||||||
# sends a commit message to the server
|
# sends a commit message to the server
|
||||||
|
@ -150,4 +150,13 @@ 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
|
end
|
||||||
|
|
|
@ -18,5 +18,6 @@ require 'solr/request/delete'
|
||||||
require 'solr/request/ping'
|
require 'solr/request/ping'
|
||||||
require 'solr/request/select'
|
require 'solr/request/select'
|
||||||
require 'solr/request/standard'
|
require 'solr/request/standard'
|
||||||
|
require 'solr/request/dismax'
|
||||||
require 'solr/request/update'
|
require 'solr/request/update'
|
||||||
require 'solr/request/index_info'
|
require 'solr/request/index_info'
|
||||||
|
|
|
@ -17,6 +17,7 @@ require 'solr/response/ruby'
|
||||||
require 'solr/response/ping'
|
require 'solr/response/ping'
|
||||||
require 'solr/response/add_document'
|
require 'solr/response/add_document'
|
||||||
require 'solr/response/standard'
|
require 'solr/response/standard'
|
||||||
|
require 'solr/response/dismax'
|
||||||
require 'solr/response/commit'
|
require 'solr/response/commit'
|
||||||
require 'solr/response/delete'
|
require 'solr/response/delete'
|
||||||
require 'solr/response/index_info'
|
require 'solr/response/index_info'
|
|
@ -237,6 +237,30 @@
|
||||||
</lst>
|
</lst>
|
||||||
</requestHandler>
|
</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
|
<!-- queryResponseWriter plugins... query responses will be written using the
|
||||||
writer specified by the 'wt' request parameter matching the name of a registered
|
writer specified by the 'wt' request parameter matching the name of a registered
|
||||||
writer.
|
writer.
|
||||||
|
|
|
@ -42,6 +42,11 @@ class ServerTest < Test::Unit::TestCase
|
||||||
assert_equal 1, response.total_hits
|
assert_equal 1, response.total_hits
|
||||||
assert_equal '123456', response.hits[0]['id']
|
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
|
# delete it
|
||||||
@connection.delete(123456)
|
@connection.delete(123456)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue