01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.solr.handler;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import org.apache.solr.core.SolrCore;
22: import org.apache.solr.request.LocalSolrQueryRequest;
23: import org.apache.solr.request.MapSolrParams;
24: import org.apache.solr.request.SolrParams;
25: import org.apache.solr.request.SolrQueryRequest;
26: import org.apache.solr.util.AbstractSolrTestCase;
27:
28: /**
29: * Most of the tests for StandardRequestHandler are in ConvertedLegacyTest
30: *
31: */
32: public class StandardRequestHandlerTest extends AbstractSolrTestCase {
33:
34: @Override
35: public String getSchemaFile() {
36: return "schema.xml";
37: }
38:
39: @Override
40: public String getSolrConfigFile() {
41: return "solrconfig.xml";
42: }
43:
44: @Override
45: public void setUp() throws Exception {
46: super .setUp();
47: lrf = h.getRequestFactory("standard", 0, 20);
48: }
49:
50: public void testSorting() throws Exception {
51: assertU(adoc("id", "10", "title", "test", "val_s", "aaa"));
52: assertU(adoc("id", "11", "title", "test", "val_s", "bbb"));
53: assertU(adoc("id", "12", "title", "test", "val_s", "ccc"));
54: assertU(commit());
55:
56: Map<String, String> args = new HashMap<String, String>();
57: args.put(SolrParams.Q, "title:test");
58: args.put("indent", "true");
59: SolrQueryRequest req = new LocalSolrQueryRequest(SolrCore
60: .getSolrCore(), new MapSolrParams(args));
61:
62: assertQ("Make sure they got in", req, "//*[@numFound='3']");
63:
64: args.put(SolrParams.SORT, "val_s asc");
65: assertQ("with sort param [asc]", req, "//*[@numFound='3']",
66: "//result/doc[1]/int[@name='id'][.='10']",
67: "//result/doc[2]/int[@name='id'][.='11']",
68: "//result/doc[3]/int[@name='id'][.='12']");
69:
70: args.put(SolrParams.SORT, "val_s desc");
71: assertQ("with sort param [desc]", req, "//*[@numFound='3']",
72: "//result/doc[1]/int[@name='id'][.='12']",
73: "//result/doc[2]/int[@name='id'][.='11']",
74: "//result/doc[3]/int[@name='id'][.='10']");
75:
76: // Using legacy ';' param
77: args.remove(SolrParams.SORT);
78: args.put(SolrParams.Q, "title:test; val_s desc");
79: assertQ("with sort param [desc]", req, "//*[@numFound='3']",
80: "//result/doc[1]/int[@name='id'][.='12']",
81: "//result/doc[2]/int[@name='id'][.='11']",
82: "//result/doc[3]/int[@name='id'][.='10']");
83:
84: args.put(SolrParams.Q, "title:test; val_s asc");
85: assertQ("with sort param [desc]", req, "//*[@numFound='3']",
86: "//result/doc[1]/int[@name='id'][.='10']",
87: "//result/doc[2]/int[@name='id'][.='11']",
88: "//result/doc[3]/int[@name='id'][.='12']");
89: }
90: }
|