01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.lucene.benchmark.quality.utils;
17:
18: import org.apache.lucene.analysis.standard.StandardAnalyzer;
19: import org.apache.lucene.benchmark.quality.QualityQuery;
20: import org.apache.lucene.benchmark.quality.QualityQueryParser;
21: import org.apache.lucene.queryParser.ParseException;
22: import org.apache.lucene.queryParser.QueryParser;
23: import org.apache.lucene.search.Query;
24:
25: /**
26: * Simplistic quality query parser. A Lucene query is created by passing
27: * the value of the specified QualityQuery name-value pair into
28: * a Lucene's QueryParser using StandardAnalyzer. */
29: public class SimpleQQParser implements QualityQueryParser {
30:
31: private String qqName;
32: private String indexField;
33: ThreadLocal queryParser = new ThreadLocal();
34:
35: /**
36: * Constructor of a simple qq parser.
37: * @param qqName name-value pair of quality query to use for creating the query
38: * @param indexField corresponding index field
39: */
40: public SimpleQQParser(String qqName, String indexField) {
41: this .qqName = qqName;
42: this .indexField = indexField;
43: }
44:
45: /* (non-Javadoc)
46: * @see org.apache.lucene.benchmark.quality.QualityQueryParser#parse(org.apache.lucene.benchmark.quality.QualityQuery)
47: */
48: public Query parse(QualityQuery qq) throws ParseException {
49: QueryParser qp = (QueryParser) queryParser.get();
50: if (qp == null) {
51: qp = new QueryParser(indexField, new StandardAnalyzer());
52: queryParser.set(qp);
53: }
54: return qp.parse(qq.getValue(qqName));
55: }
56:
57: }
|