1 package org.apache.lucene.benchmark.byTask.feeds;
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 java.util.ArrayList;
21 import java.util.StringTokenizer;
23 import org.apache.lucene.index.Term;
24 import org.apache.lucene.search.PhraseQuery;
25 import org.apache.lucene.search.Query;
28 * Create sloppy phrase queries for performance test, in an index created using simple doc maker.
30 public class SimpleSloppyPhraseQueryMaker extends SimpleQueryMaker {
33 * @see org.apache.lucene.benchmark.byTask.feeds.SimpleQueryMaker#prepareQueries()
36 protected Query[] prepareQueries() throws Exception {
37 // extract some 100 words from doc text to an array
39 ArrayList<String> w = new ArrayList<String>();
40 StringTokenizer st = new StringTokenizer(SingleDocSource.DOC_TEXT);
41 while (st.hasMoreTokens() && w.size()<100) {
42 w.add(st.nextToken());
44 words = w.toArray(new String[0]);
46 // create queries (that would find stuff) with varying slops
47 ArrayList<Query> queries = new ArrayList<Query>();
48 for (int slop=0; slop<8; slop++) {
49 for (int qlen=2; qlen<6; qlen++) {
50 for (int wd=0; wd<words.length-qlen-slop; wd++) {
52 int remainedSlop = slop;
53 PhraseQuery q = new PhraseQuery();
56 for (int i=0; i<qlen; i++) {
57 q.add(new Term(DocMaker.BODY_FIELD,words[wind++]));
66 q = new PhraseQuery();
67 q.setSlop(slop+2*qlen);
68 wind = wd+qlen+remainedSlop-1;
69 for (int i=0; i<qlen; i++) {
70 q.add(new Term(DocMaker.BODY_FIELD,words[wind--]));
80 return queries.toArray(new Query[0]);