~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/search/function/SortByFunctionTest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.search.function;
2
 
/**
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
9
 
 *
10
 
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 
 *
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.
17
 
 */
18
 
 
19
 
import org.apache.solr.util.AbstractSolrTestCase;
20
 
 
21
 
 
22
 
/**
23
 
 *
24
 
 *
25
 
 **/
26
 
public class SortByFunctionTest extends AbstractSolrTestCase {
27
 
  @Override
28
 
  public String getSchemaFile() {
29
 
    return "schema.xml";
30
 
  }
31
 
 
32
 
  @Override
33
 
  public String getSolrConfigFile() {
34
 
    return "solrconfig.xml";
35
 
  }
36
 
 
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"));
42
 
    assertU(commit());
43
 
 
44
 
    assertQ(req("fl", "*,score", "q", "*:*"),
45
 
            "//*[@numFound='4']",
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']"
51
 
    );
52
 
    assertQ(req("fl", "*,score", "q", "*:*", "sort", "score desc"),
53
 
            "//*[@numFound='4']",
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']"
59
 
    );
60
 
    assertQ(req("fl", "id,score", "q", "f_t:ipod", "sort", "score desc"),
61
 
            "//*[@numFound='4']",
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']"
66
 
    );
67
 
 
68
 
 
69
 
    assertQ(req("fl", "*,score", "q", "*:*", "sort", "sum(x_td1, y_td1) desc"),
70
 
            "//*[@numFound='4']",
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']"
76
 
    );
77
 
    assertQ(req("fl", "*,score", "q", "*:*", "sort", "sum(x_td1, y_td1) asc"),
78
 
            "//*[@numFound='4']",
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']"
84
 
    );
85
 
    //the function is equal, w_td1 separates
86
 
    assertQ(req("q", "*:*", "fl", "id", "sort", "sum(z_td1, y_td1) asc, w_td1 asc"),
87
 
            "//*[@numFound='4']",
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']"
92
 
    );
93
 
  }
94
 
}