2007-01-14 20:41:18 -05:00
|
|
|
# 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 StandardRequestTest < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def test_basic_query
|
|
|
|
request = Solr::Request::Standard.new(:query => 'query')
|
|
|
|
assert_equal :ruby, request.response_format
|
|
|
|
assert_equal 'select', request.handler
|
|
|
|
assert_equal 'query', request.to_hash[:q]
|
|
|
|
assert_match /q=query/, request.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_bad_params
|
|
|
|
assert_raise(RuntimeError) do
|
|
|
|
Solr::Request::Standard.new(:foo => "invalid")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise(RuntimeError) do
|
|
|
|
Solr::Request::Standard.new(:query => "valid", :foo => "invalid")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_common_params
|
|
|
|
request = Solr::Request::Standard.new(:query => 'query', :start => 10, :rows => 50,
|
|
|
|
:filter_queries => ['fq1', 'fq2'], :field_list => ['id','title','score'])
|
|
|
|
assert_equal 10, request.to_hash[:start]
|
|
|
|
assert_equal 50, request.to_hash[:rows]
|
|
|
|
assert_equal ['fq1','fq2'], request.to_hash[:fq]
|
|
|
|
assert_equal "id,title,score", request.to_hash[:fl]
|
|
|
|
end
|
2007-01-16 16:28:44 -05:00
|
|
|
|
2007-01-17 02:57:48 -05:00
|
|
|
def test_missing_params
|
|
|
|
request = Solr::Request::Standard.new(:query => 'query', :debug_query => false, :facets => {:fields =>[:category_facet]})
|
2007-01-16 16:28:44 -05:00
|
|
|
assert_nil request.to_hash[:rows]
|
|
|
|
assert_no_match /rows/, request.to_s
|
2007-01-17 02:57:48 -05:00
|
|
|
assert_no_match /facet\.sort/, request.to_s
|
2007-01-16 16:28:44 -05:00
|
|
|
assert_match /debugQuery/, request.to_s
|
|
|
|
end
|
2007-01-14 20:41:18 -05:00
|
|
|
|
2007-01-16 16:28:44 -05:00
|
|
|
def test_facet_params_all
|
2007-01-14 20:41:18 -05:00
|
|
|
request = Solr::Request::Standard.new(:query => 'query',
|
|
|
|
:facets => {
|
|
|
|
:fields => [:genre,
|
2007-01-17 02:57:48 -05:00
|
|
|
{:year => {:limit => 50, :mincount => 0, :missing => false, :sort => :term}}], # field that overrides the global facet parameters
|
2007-01-14 20:41:18 -05:00
|
|
|
:queries => ["q1", "q2"],
|
2007-01-17 02:57:48 -05:00
|
|
|
:limit => 5, :zeros => true, :mincount => 20, :sort => :count # global facet parameters
|
2007-01-14 20:41:18 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
assert_equal true, request.to_hash[:facet]
|
|
|
|
assert_equal [:genre, :year], request.to_hash[:"facet.field"]
|
|
|
|
assert_equal ["q1", "q2"], request.to_hash[:"facet.query"]
|
|
|
|
assert_equal 5, request.to_hash[:"facet.limit"]
|
2007-01-17 02:57:48 -05:00
|
|
|
assert_equal 20, request.to_hash[:"facet.mincount"]
|
|
|
|
assert_equal true, request.to_hash[:"facet.sort"]
|
2007-01-14 20:41:18 -05:00
|
|
|
assert_equal 50, request.to_hash[:"f.year.facet.limit"]
|
2007-01-17 02:57:48 -05:00
|
|
|
assert_equal 0, request.to_hash[:"f.year.facet.mincount"]
|
|
|
|
assert_equal false, request.to_hash[:"f.year.facet.sort"]
|
2007-01-14 20:41:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_basic_sort
|
|
|
|
request = Solr::Request::Standard.new(:query => 'query', :sort => [{:title => :descending}])
|
|
|
|
assert_equal 'query;title desc', request.to_hash[:q]
|
|
|
|
end
|
2007-01-16 17:02:13 -05:00
|
|
|
|
2007-01-14 20:41:18 -05:00
|
|
|
end
|