1
package org.apache.solr;
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
11
* http://www.apache.org/licenses/LICENSE-2.0
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.
20
import org.apache.solr.client.solrj.SolrServerException;
21
import org.apache.solr.common.params.CommonParams;
22
import org.apache.solr.common.params.ModifiableSolrParams;
24
import java.util.ArrayList;
25
import java.util.HashSet;
26
import java.util.List;
31
* http://docs.codehaus.org/display/JETTY/ServletTester
32
* rather then open a real connection?
36
public class TestDistributedGrouping extends BaseDistributedSearchTestCase {
41
String tlong = "other_tl1";
42
String tdate_a = "a_n_tdt";
43
String tdate_b = "b_n_tdt";
44
String oddField="oddField_s";
46
public void doTest() throws Exception {
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);
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");
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;
99
indexr(id, 17, "SubjectTerms_mfacet", vals);
101
for (int i=100; i<150; i++) {
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);
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");
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);
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");
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);
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);
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());