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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.lucene.benchmark.quality.utils;
19 import org.apache.lucene.analysis.standard.StandardAnalyzer;
20 import org.apache.lucene.benchmark.quality.QualityQuery;
21 import org.apache.lucene.benchmark.quality.QualityQueryParser;
22 import org.apache.lucene.queryParser.ParseException;
23 import org.apache.lucene.queryParser.QueryParser;
24 import org.apache.lucene.search.BooleanClause;
25 import org.apache.lucene.search.BooleanQuery;
26 import org.apache.lucene.search.Query;
27 import org.apache.lucene.util.Version;
30 * Simplistic quality query parser. A Lucene query is created by passing
31 * the value of the specified QualityQuery name-value pair(s) into
32 * a Lucene's QueryParser using StandardAnalyzer. */
33 public class SimpleQQParser implements QualityQueryParser {
35 private String qqNames[];
36 private String indexField;
37 ThreadLocal<QueryParser> queryParser = new ThreadLocal<QueryParser>();
40 * Constructor of a simple qq parser.
41 * @param qqNames name-value pairs of quality query to use for creating the query
42 * @param indexField corresponding index field
44 public SimpleQQParser(String qqNames[], String indexField) {
45 this.qqNames = qqNames;
46 this.indexField = indexField;
50 * Constructor of a simple qq parser.
51 * @param qqName name-value pair of quality query to use for creating the query
52 * @param indexField corresponding index field
54 public SimpleQQParser(String qqName, String indexField) {
55 this(new String[] { qqName }, indexField);
59 * @see org.apache.lucene.benchmark.quality.QualityQueryParser#parse(org.apache.lucene.benchmark.quality.QualityQuery)
61 public Query parse(QualityQuery qq) throws ParseException {
62 QueryParser qp = queryParser.get();
64 qp = new QueryParser(Version.LUCENE_CURRENT, indexField, new StandardAnalyzer(Version.LUCENE_CURRENT));
67 BooleanQuery bq = new BooleanQuery();
68 for (int i = 0; i < qqNames.length; i++)
69 bq.add(qp.parse(QueryParser.escape(qq.getValue(qqNames[i]))), BooleanClause.Occur.SHOULD);