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

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/search/TestSearchPerf.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
 
/**
2
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     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
 
 */
17
 
 
18
 
package org.apache.solr.search;
19
 
 
20
 
import org.apache.lucene.index.Term;
21
 
import org.apache.lucene.search.*;
22
 
import org.apache.solr.util.AbstractSolrTestCase;
23
 
import org.apache.solr.request.SolrQueryRequest;
24
 
import org.apache.solr.response.SolrQueryResponse;
25
 
import org.apache.solr.update.processor.UpdateRequestProcessorChain;
26
 
import org.apache.solr.update.processor.UpdateRequestProcessor;
27
 
import org.apache.solr.update.AddUpdateCommand;
28
 
import org.apache.solr.common.SolrInputDocument;
29
 
 
30
 
import java.util.*;
31
 
import java.io.IOException;
32
 
 
33
 
/**
34
 
 * @version $Id: TestSearchPerf.java 1140724 2011-06-28 17:00:20Z yonik $
35
 
 */
36
 
public class TestSearchPerf extends AbstractSolrTestCase {
37
 
 
38
 
  @Override
39
 
  public String getSchemaFile() { return "schema11.xml"; }
40
 
  @Override
41
 
  public String getSolrConfigFile() { return "solrconfig.xml"; }
42
 
 
43
 
  @Override
44
 
  public void setUp() throws Exception {
45
 
    super.setUp();
46
 
  }
47
 
  @Override
48
 
  public void tearDown() throws Exception {
49
 
    super.tearDown();
50
 
  }
51
 
 
52
 
  String t(int tnum) {
53
 
    return String.format("%08d", tnum);
54
 
  }
55
 
 
56
 
  Random r = new Random(0);  // specific seed for reproducible perf testing
57
 
  int nDocs;
58
 
  void createIndex(int nDocs) {
59
 
    this.nDocs = nDocs;
60
 
    assertU(delQ("*:*"));
61
 
    for (int i=0; i<nDocs; i++) {
62
 
      assertU(adoc("id", Float.toString(i)
63
 
 //             ,"foo1_s",t(0)
64
 
 //             ,"foo2_s",t(r.nextInt(2))
65
 
 //             ,"foo4_s",t(r.nextInt(3))
66
 
              ,"foomany_s",t(r.nextInt(nDocs*10))
67
 
      ));
68
 
    }
69
 
    // assertU(optimize()); // squeeze out any possible deleted docs
70
 
    assertU(commit());
71
 
  }
72
 
 
73
 
 
74
 
  // Skip encoding for updating the index
75
 
  void createIndex2(int nDocs, String... fields) throws IOException {
76
 
    Set<String> fieldSet = new HashSet<String>(Arrays.asList(fields));
77
 
 
78
 
    SolrQueryRequest req = lrf.makeRequest();
79
 
    SolrQueryResponse rsp = new SolrQueryResponse();
80
 
    UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessingChain(null);
81
 
    UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp);
82
 
 
83
 
    boolean foomany_s = fieldSet.contains("foomany_s");
84
 
    boolean foo1_s = fieldSet.contains("foo1_s");
85
 
    boolean foo2_s = fieldSet.contains("foo2_s");
86
 
    boolean foo4_s = fieldSet.contains("foo4_s");
87
 
    boolean foo8_s = fieldSet.contains("foo8_s");
88
 
    boolean t10_100_ws = fieldSet.contains("t10_100_ws");
89
 
 
90
 
    
91
 
    for (int i=0; i<nDocs; i++) {
92
 
      SolrInputDocument doc = new SolrInputDocument();
93
 
      doc.addField("id",Float.toString(i));
94
 
      if (foomany_s) {
95
 
        doc.addField("foomany_s",t(r.nextInt(nDocs*10)));
96
 
      }
97
 
      if (foo1_s) {
98
 
        doc.addField("foo1_s",t(0));
99
 
      }
100
 
      if (foo2_s) {
101
 
        doc.addField("foo2_s",r.nextInt(2));
102
 
      }
103
 
      if (foo4_s) {
104
 
        doc.addField("foo4_s",r.nextInt(4));
105
 
      }
106
 
      if (foo8_s) {
107
 
        doc.addField("foo8_s",r.nextInt(8));
108
 
      }
109
 
      if (t10_100_ws) {
110
 
        StringBuilder sb = new StringBuilder(9*100);
111
 
        for (int j=0; j<100; j++) {
112
 
          sb.append(' ');
113
 
          sb.append(t(r.nextInt(10)));
114
 
        }
115
 
        doc.addField("t10_100_ws", sb.toString());
116
 
      }
117
 
 
118
 
      AddUpdateCommand cmd = new AddUpdateCommand();
119
 
      cmd.solrDoc = doc;
120
 
      processor.processAdd(cmd);
121
 
    }
122
 
    processor.finish();
123
 
    req.close();
124
 
 
125
 
    assertU(commit());
126
 
 
127
 
    req = lrf.makeRequest();
128
 
    assertEquals(nDocs, req.getSearcher().maxDoc());
129
 
    req.close();
130
 
  }
131
 
 
132
 
 
133
 
  int doSetGen(int iter, Query q) throws Exception {
134
 
    SolrQueryRequest req = lrf.makeRequest();
135
 
 
136
 
    SolrIndexSearcher searcher = req.getSearcher();
137
 
 
138
 
    long start = System.currentTimeMillis();
139
 
 
140
 
    int ret = 0;
141
 
    for (int i=0; i<iter; i++) {
142
 
      DocSet set = searcher.getDocSetNC(q, null);
143
 
      ret += set.size();
144
 
    }
145
 
 
146
 
    long end = System.currentTimeMillis();
147
 
    System.out.println("ret="+ret+ " time="+(end-start)+" throughput="+iter*1000/(end-start+1));
148
 
 
149
 
    req.close();
150
 
    assertTrue(ret>0);  // make sure we did some work
151
 
    return ret;
152
 
  }
153
 
 
154
 
  int doListGen(int iter, Query q, List<Query> filt, boolean cacheQuery, boolean cacheFilt) throws Exception {
155
 
    SolrQueryRequest req = lrf.makeRequest();
156
 
 
157
 
    SolrIndexSearcher searcher = req.getSearcher();
158
 
 
159
 
    long start = System.currentTimeMillis();
160
 
 
161
 
    // These aren't public in SolrIndexSearcher
162
 
    int NO_CHECK_QCACHE       = 0x80000000;
163
 
    int GET_DOCSET            = 0x40000000;
164
 
    int NO_CHECK_FILTERCACHE  = 0x20000000;
165
 
    int GET_SCORES            = 0x01;
166
 
 
167
 
    int ret = 0;
168
 
    for (int i=0; i<iter; i++) {
169
 
      DocList l = searcher.getDocList(q, filt, (Sort)null, 0, 10, (cacheQuery?0:NO_CHECK_QCACHE)|(cacheFilt?0:NO_CHECK_FILTERCACHE) );
170
 
      ret += l.matches();
171
 
    }
172
 
 
173
 
    long end = System.currentTimeMillis();
174
 
    System.out.println("ret="+ret+ " time="+(end-start)+" throughput="+iter*1000/(end-start+1));
175
 
 
176
 
    req.close();
177
 
    assertTrue(ret>0);  // make sure we did some work
178
 
    return ret;
179
 
  }
180
 
 
181
 
  // prevent complaints by junit
182
 
  public void testEmpty() {
183
 
  }
184
 
 
185
 
  public void XtestSetGenerationPerformance() throws Exception {
186
 
    createIndex(49999);
187
 
    doSetGen(10000, new TermQuery(new Term("foo1_s",t(0))) );
188
 
 
189
 
    BooleanQuery bq = new BooleanQuery();
190
 
    bq.add(new TermQuery(new Term("foo2_s",t(0))), BooleanClause.Occur.SHOULD);
191
 
    bq.add(new TermQuery(new Term("foo2_s",t(1))), BooleanClause.Occur.SHOULD);
192
 
    doSetGen(5000, bq); 
193
 
  }
194
 
 
195
 
  /** test range query performance */
196
 
  public void XtestRangePerformance() throws Exception {
197
 
    int indexSize=1999;
198
 
    float fractionCovered=1.0f;
199
 
 
200
 
    String l=t(0);
201
 
    String u=t((int)(indexSize*10*fractionCovered));   
202
 
 
203
 
    SolrQueryRequest req = lrf.makeRequest();
204
 
    QParser parser = QParser.getParser("foomany_s:[" + l + " TO " + u + "]", null, req);
205
 
    Query range = parser.getQuery();
206
 
                                     
207
 
    QParser parser2 = QParser.getParser("{!frange l="+l+" u="+u+"}foomany_s", null, req);
208
 
    Query frange = parser2.getQuery();
209
 
    req.close();
210
 
 
211
 
    createIndex2(indexSize,"foomany_s");
212
 
 
213
 
    doSetGen(1, range);
214
 
    doSetGen(1, frange);   // load field cache
215
 
 
216
 
    doSetGen(100, range);
217
 
    doSetGen(10000, frange);
218
 
  }
219
 
 
220
 
  /** test range query performance */
221
 
  public void XtestFilteringPerformance() throws Exception {
222
 
    int indexSize=19999;
223
 
    float fractionCovered=.1f;
224
 
 
225
 
    String l=t(0);
226
 
    String u=t((int)(indexSize*10*fractionCovered));
227
 
 
228
 
    SolrQueryRequest req = lrf.makeRequest();
229
 
 
230
 
    QParser parser = QParser.getParser("foomany_s:[" + l + " TO " + u + "]", null, req);
231
 
    Query rangeQ = parser.getQuery();
232
 
    List<Query> filters = new ArrayList<Query>();
233
 
    filters.add(rangeQ);
234
 
    req.close();
235
 
 
236
 
    parser = QParser.getParser("{!dismax qf=t10_100_ws pf=t10_100_ws ps=20}"+ t(0) + ' ' + t(1) + ' ' + t(2), null, req);
237
 
    Query q= parser.getQuery();
238
 
 
239
 
    // SolrIndexSearcher searcher = req.getSearcher();
240
 
    // DocSet range = searcher.getDocSet(rangeQ, null);
241
 
 
242
 
    createIndex2(indexSize, "foomany_s", "t10_100_ws");
243
 
 
244
 
    // doListGen(100, q, filters, false, true);
245
 
    doListGen(500, q, filters, false, true);
246
 
 
247
 
    req.close();
248
 
  }  
249
 
 
250
 
 
251
 
}
 
 
b'\\ No newline at end of file'