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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/TestDistributedGrouping.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;
2
 
 
3
 
/*
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
import org.apache.solr.client.solrj.SolrServerException;
21
 
import org.apache.solr.common.params.CommonParams;
22
 
import org.apache.solr.common.params.ModifiableSolrParams;
23
 
 
24
 
import java.util.ArrayList;
25
 
import java.util.HashSet;
26
 
import java.util.List;
27
 
import java.util.Set;
28
 
 
29
 
/**
30
 
 * TODO? perhaps use:
31
 
 *  http://docs.codehaus.org/display/JETTY/ServletTester
32
 
 * rather then open a real connection?
33
 
 *
34
 
 * @since solr 3.5
35
 
 */
36
 
public class TestDistributedGrouping extends BaseDistributedSearchTestCase {
37
 
 
38
 
  String t1="a_t";
39
 
  String s1="1_a_s1";
40
 
  String s2="2_a_s1";
41
 
  String tlong = "other_tl1";
42
 
  String tdate_a = "a_n_tdt";
43
 
  String tdate_b = "b_n_tdt";
44
 
  String oddField="oddField_s";
45
 
 
46
 
  public void doTest() throws Exception {
47
 
    del("*:*");
48
 
    commit();
49
 
 
50
 
    handle.clear();
51
 
    handle.put("QTime", SKIPVAL);
52
 
    handle.put("timestamp", SKIPVAL);
53
 
    // Test distributed grouping with empty indices
54
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc");
55
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "hl","true","hl.fl",t1);
56
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "facet", "true", "facet.field", t1);
57
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "stats", "true", "stats.field", tlong);
58
 
    query("q", "kings", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "spellcheck", "true", "spellcheck.build", "true", "qt", "spellCheckCompRH");
59
 
    query("q", "*:*", "fq", s2 + ":a", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.truncate", "true", "facet", "true", "facet.field", t1);
60
 
 
61
 
    indexr(id,1, s1, 100, tlong, 100,t1,"now is the time for all good men",
62
 
           tdate_a, "2010-04-20T11:00:00Z",
63
 
           tdate_b, "2009-08-20T11:00:00Z",
64
 
           "foo_f", 1.414f, "foo_b", "true", "foo_d", 1.414d);
65
 
    indexr(id,2, s1, 50 , tlong, 50,t1,"to come to the aid of their country.",
66
 
           tdate_a, "2010-05-02T11:00:00Z",
67
 
           tdate_b, "2009-11-02T11:00:00Z");
68
 
    indexr(id,3, s1, 2, tlong, 2,t1,"how now brown cow",
69
 
           tdate_a, "2010-05-03T11:00:00Z");
70
 
    indexr(id,4, s1, -100 ,tlong, 101,
71
 
           t1,"the quick fox jumped over the lazy dog", 
72
 
           tdate_a, "2010-05-03T11:00:00Z",
73
 
           tdate_b, "2010-05-03T11:00:00Z");
74
 
    indexr(id,5, s1, 500, tlong, 500 ,
75
 
           t1,"the quick fox jumped way over the lazy dog", 
76
 
           tdate_a, "2010-05-05T11:00:00Z");
77
 
    indexr(id,6, s1, -600, tlong, 600 ,t1,"humpty dumpy sat on a wall");
78
 
    indexr(id,7, s1, 123, tlong, 123 ,t1,"humpty dumpy had a great fall");
79
 
    indexr(id,8, s1, 876, tlong, 876,
80
 
           tdate_b, "2010-01-05T11:00:00Z",
81
 
           t1,"all the kings horses and all the kings men");
82
 
    indexr(id,9, s1, 7, tlong, 7,t1,"couldn't put humpty together again");
83
 
    indexr(id,10, s1, 4321, tlong, 4321,t1,"this too shall pass");
84
 
    indexr(id,11, s1, -987, tlong, 987,
85
 
           t1,"An eye for eye only ends up making the whole world blind.");
86
 
    indexr(id,12, s1, 379, tlong, 379,
87
 
           t1,"Great works are performed, not by strength, but by perseverance.");
88
 
    indexr(id,13, s1, 232, tlong, 232,
89
 
           t1,"no eggs on wall, lesson learned", 
90
 
           oddField, "odd man out");
91
 
 
92
 
    indexr(id, 14, "SubjectTerms_mfacet", new String[]  {"mathematical models", "mathematical analysis"});
93
 
    indexr(id, 15, "SubjectTerms_mfacet", new String[]  {"test 1", "test 2", "test3"});
94
 
    indexr(id, 16, "SubjectTerms_mfacet", new String[]  {"test 1", "test 2", "test3"});
95
 
    String[] vals = new String[100];
96
 
    for (int i=0; i<100; i++) {
97
 
      vals[i] = "test " + i;
98
 
    }
99
 
    indexr(id, 17, "SubjectTerms_mfacet", vals);
100
 
 
101
 
    for (int i=100; i<150; i++) {
102
 
      indexr(id, i);      
103
 
    }
104
 
 
105
 
    int[] values = new int[]{9999, 99999, 999999, 9999999};
106
 
    for (int shard = 0; shard < clients.size(); shard++) {
107
 
      int groupValue = values[shard];
108
 
      for (int i = 500; i < 600; i++) {
109
 
        index_specific(shard, s1, groupValue, s2, "a", id, i * (shard + 1), t1, shard);
110
 
      }
111
 
    }
112
 
 
113
 
    commit();
114
 
 
115
 
          // test grouping
116
 
    // The second sort = id asc . The sorting behaviour is different in dist mode. See TopDocs#merge
117
 
    // The shard the result came from matters in the order if both document sortvalues are equal
118
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc");
119
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", "id asc, _docid_ asc");
120
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", "{!func}add(" + tlong + ",5) asc, id asc");
121
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "facet", "true", "facet.field", t1);
122
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "stats", "true", "stats.field", tlong);
123
 
    query("q", "kings", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "spellcheck", "true", "spellcheck.build", "true", "qt", "spellCheckCompRH");
124
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "facet", "true", "hl","true","hl.fl",t1);
125
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.sort", "id desc");
126
 
 
127
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.offset", 5, "group.limit", 5, "sort", s1 + " asc, id asc");
128
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "offset", 5, "rows", 5, "group.offset", 5, "group.limit", 5, "sort", s1 + " asc, id asc");
129
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "offset", 5, "rows", 5, "sort", s1 + " asc, id asc", "group.format", "simple");
130
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "offset", 5, "rows", 5, "sort", s1 + " asc, id asc", "group.main", "true");
131
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.offset", 5, "group.limit", 5, "sort", s1 + " asc, id asc", "group.format", "simple", "offset", 5, "rows", 5);
132
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.offset", 5, "group.limit", 5, "sort", s1 + " asc, id asc", "group.main", "true", "offset", 5, "rows", 5);
133
 
 
134
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.query", t1 + ":kings OR " + t1 + ":eggs", "group.limit", 10, "sort", s1 + " asc, id asc");
135
 
    query("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.query", t1 + ":kings OR " + t1 + ":eggs", "group.limit", 10, "sort", s1 + " asc, id asc");
136
 
 
137
 
    // In order to validate this we need to make sure that during indexing that all documents of one group only occur on the same shard
138
 
    query("q", "*:*", "fq", s2 + ":a", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.ngroups", "true");
139
 
    query("q", "*:*", "fq", s2 + ":a", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.truncate", "true");
140
 
    query("q", "*:*", "fq", s2 + ":a", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.truncate", "true", "facet", "true", "facet.field", t1);
141
 
 
142
 
    // We cannot validate distributed grouping with scoring as first sort. since there is no global idf. We can check if no errors occur
143
 
    simpleQuery("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10, "sort", "score desc, _docid_ asc, id asc");
144
 
    simpleQuery("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field", s1, "group.limit", 10);
145
 
  }
146
 
 
147
 
  private void simpleQuery(Object... queryParams) throws SolrServerException {
148
 
    ModifiableSolrParams params = new ModifiableSolrParams();
149
 
    for (int i = 0; i < queryParams.length; i += 2) {
150
 
      params.add(queryParams[i].toString(), queryParams[i + 1].toString());
151
 
    }
152
 
    queryServer(params);
153
 
  }
154
 
 
155
 
}