1
package org.apache.solr.search.function;
3
* Licensed to the Apache Software Foundation (ASF) under one or more
4
* contributor license agreements. See the NOTICE file distributed with
5
* this work for additional information regarding copyright ownership.
6
* The ASF licenses this file to You under the Apache License, Version 2.0
7
* (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
import org.apache.solr.util.AbstractSolrTestCase;
26
public class SortByFunctionTest extends AbstractSolrTestCase {
28
public String getSchemaFile() {
33
public String getSolrConfigFile() {
34
return "solrconfig.xml";
37
public void test() throws Exception {
38
assertU(adoc("id", "1", "x_td1", "0", "y_td1", "2", "w_td1", "25", "z_td1", "5", "f_t", "ipod"));
39
assertU(adoc("id", "2", "x_td1", "2", "y_td1", "2", "w_td1", "15", "z_td1", "5", "f_t", "ipod ipod ipod ipod ipod"));
40
assertU(adoc("id", "3", "x_td1", "3", "y_td1", "2", "w_td1", "55", "z_td1", "5", "f_t", "ipod ipod ipod ipod ipod ipod ipod ipod ipod"));
41
assertU(adoc("id", "4", "x_td1", "4", "y_td1", "2", "w_td1", "45", "z_td1", "5", "f_t", "ipod ipod ipod ipod ipod ipod ipod"));
44
assertQ(req("fl", "*,score", "q", "*:*"),
46
"//float[@name='score']='1.0'",
47
"//result/doc[1]/int[@name='id'][.='1']",
48
"//result/doc[2]/int[@name='id'][.='2']",
49
"//result/doc[3]/int[@name='id'][.='3']",
50
"//result/doc[4]/int[@name='id'][.='4']"
52
assertQ(req("fl", "*,score", "q", "*:*", "sort", "score desc"),
54
"//float[@name='score']='1.0'",
55
"//result/doc[1]/int[@name='id'][.='1']",
56
"//result/doc[2]/int[@name='id'][.='2']",
57
"//result/doc[3]/int[@name='id'][.='3']",
58
"//result/doc[4]/int[@name='id'][.='4']"
60
assertQ(req("fl", "id,score", "q", "f_t:ipod", "sort", "score desc"),
62
"//result/doc[1]/int[@name='id'][.='1']",
63
"//result/doc[2]/int[@name='id'][.='4']",
64
"//result/doc[3]/int[@name='id'][.='2']",
65
"//result/doc[4]/int[@name='id'][.='3']"
69
assertQ(req("fl", "*,score", "q", "*:*", "sort", "sum(x_td1, y_td1) desc"),
71
"//float[@name='score']='1.0'",
72
"//result/doc[1]/int[@name='id'][.='4']",
73
"//result/doc[2]/int[@name='id'][.='3']",
74
"//result/doc[3]/int[@name='id'][.='2']",
75
"//result/doc[4]/int[@name='id'][.='1']"
77
assertQ(req("fl", "*,score", "q", "*:*", "sort", "sum(x_td1, y_td1) asc"),
79
"//float[@name='score']='1.0'",
80
"//result/doc[1]/int[@name='id'][.='1']",
81
"//result/doc[2]/int[@name='id'][.='2']",
82
"//result/doc[3]/int[@name='id'][.='3']",
83
"//result/doc[4]/int[@name='id'][.='4']"
85
//the function is equal, w_td1 separates
86
assertQ(req("q", "*:*", "fl", "id", "sort", "sum(z_td1, y_td1) asc, w_td1 asc"),
88
"//result/doc[1]/int[@name='id'][.='2']",
89
"//result/doc[2]/int[@name='id'][.='1']",
90
"//result/doc[3]/int[@name='id'][.='4']",
91
"//result/doc[4]/int[@name='id'][.='3']"