mirror of https://github.com/apache/lucene.git
Add support for new facet.prefix feature
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@499218 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2f37fb1633
commit
39c8be6447
|
@ -66,6 +66,7 @@ module Solr
|
||||||
|
|
||||||
# facet parameter processing
|
# facet parameter processing
|
||||||
if @params[:facets]
|
if @params[:facets]
|
||||||
|
# TODO need validation of all that is under the :facets Hash too
|
||||||
hash[:facet] = true
|
hash[:facet] = true
|
||||||
hash[:"facet.field"] = []
|
hash[:"facet.field"] = []
|
||||||
hash[:"facet.query"] = @params[:facets][:queries]
|
hash[:"facet.query"] = @params[:facets][:queries]
|
||||||
|
@ -73,6 +74,7 @@ module Solr
|
||||||
hash[:"facet.limit"] = @params[:facets][:limit]
|
hash[:"facet.limit"] = @params[:facets][:limit]
|
||||||
hash[:"facet.missing"] = @params[:facets][:missing]
|
hash[:"facet.missing"] = @params[:facets][:missing]
|
||||||
hash[:"facet.mincount"] = @params[:facets][:mincount]
|
hash[:"facet.mincount"] = @params[:facets][:mincount]
|
||||||
|
hash[:"facet.prefix"] = @params[:facets][:prefix]
|
||||||
@params[:facets][:fields].each do |f|
|
@params[:facets][:fields].each do |f|
|
||||||
if f.kind_of? Hash
|
if f.kind_of? Hash
|
||||||
key = f.keys[0]
|
key = f.keys[0]
|
||||||
|
@ -82,6 +84,7 @@ module Solr
|
||||||
hash[:"f.#{key}.facet.limit"] = value[:limit]
|
hash[:"f.#{key}.facet.limit"] = value[:limit]
|
||||||
hash[:"f.#{key}.facet.missing"] = value[:missing]
|
hash[:"f.#{key}.facet.missing"] = value[:missing]
|
||||||
hash[:"f.#{key}.facet.mincount"] = value[:mincount]
|
hash[:"f.#{key}.facet.mincount"] = value[:mincount]
|
||||||
|
hash[:"f.#{key}.facet.prefix"] = value[:prefix]
|
||||||
else
|
else
|
||||||
hash[:"facet.field"] << f
|
hash[:"facet.field"] << f
|
||||||
end
|
end
|
||||||
|
|
Binary file not shown.
|
@ -58,21 +58,27 @@ class StandardRequestTest < Test::Unit::TestCase
|
||||||
def test_facet_params_all
|
def test_facet_params_all
|
||||||
request = Solr::Request::Standard.new(:query => 'query',
|
request = Solr::Request::Standard.new(:query => 'query',
|
||||||
:facets => {
|
:facets => {
|
||||||
:fields => [:genre,
|
:fields => [:genre,
|
||||||
{:year => {:limit => 50, :mincount => 0, :missing => false, :sort => :term}}], # field that overrides the global facet parameters
|
# field that overrides the global facet parameters
|
||||||
|
{:year => {:limit => 50, :mincount => 0, :missing => false, :sort => :term, :prefix=>"199"}}],
|
||||||
:queries => ["q1", "q2"],
|
:queries => ["q1", "q2"],
|
||||||
|
:prefix => "cat",
|
||||||
:limit => 5, :zeros => true, :mincount => 20, :sort => :count # global facet parameters
|
:limit => 5, :zeros => true, :mincount => 20, :sort => :count # global facet parameters
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
assert_equal true, request.to_hash[:facet]
|
|
||||||
assert_equal [:genre, :year], request.to_hash[:"facet.field"]
|
hash = request.to_hash
|
||||||
assert_equal ["q1", "q2"], request.to_hash[:"facet.query"]
|
assert_equal true, hash[:facet]
|
||||||
assert_equal 5, request.to_hash[:"facet.limit"]
|
assert_equal [:genre, :year], hash[:"facet.field"]
|
||||||
assert_equal 20, request.to_hash[:"facet.mincount"]
|
assert_equal ["q1", "q2"], hash[:"facet.query"]
|
||||||
assert_equal true, request.to_hash[:"facet.sort"]
|
assert_equal 5, hash[:"facet.limit"]
|
||||||
assert_equal 50, request.to_hash[:"f.year.facet.limit"]
|
assert_equal 20, hash[:"facet.mincount"]
|
||||||
assert_equal 0, request.to_hash[:"f.year.facet.mincount"]
|
assert_equal true, hash[:"facet.sort"]
|
||||||
assert_equal false, request.to_hash[:"f.year.facet.sort"]
|
assert_equal "cat", hash[:"facet.prefix"]
|
||||||
|
assert_equal 50, hash[:"f.year.facet.limit"]
|
||||||
|
assert_equal 0, hash[:"f.year.facet.mincount"]
|
||||||
|
assert_equal false, hash[:"f.year.facet.sort"]
|
||||||
|
assert_equal "199", hash[:"f.year.facet.prefix"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_basic_sort
|
def test_basic_sort
|
||||||
|
|
Loading…
Reference in New Issue