01: package org.apache.lucene.queryParser.surround.query;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
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.
18: */
19:
20: import org.apache.lucene.queryParser.surround.parser.ParseException;
21: import org.apache.lucene.queryParser.surround.parser.QueryParser;
22:
23: public class ExceptionQueryTst {
24: private String queryText;
25: private boolean verbose;
26:
27: public ExceptionQueryTst(String queryText, boolean verbose) {
28: this .queryText = queryText;
29: this .verbose = verbose;
30: }
31:
32: public void doTest(StringBuffer failQueries) {
33: boolean pass = false;
34: SrndQuery lq = null;
35: try {
36: lq = QueryParser.parse(queryText);
37: if (verbose) {
38: System.out.println("Query: " + queryText
39: + "\nParsed as: " + lq.toString());
40: }
41: } catch (ParseException e) {
42: if (verbose) {
43: System.out.println("Parse exception for query:\n"
44: + queryText + "\n" + e.getMessage());
45: }
46: pass = true;
47: }
48: if (!pass) {
49: failQueries.append(queryText);
50: failQueries.append("\nParsed as: ");
51: failQueries.append(lq.toString());
52: failQueries.append("\n");
53: }
54: }
55:
56: public static String getFailQueries(String[] exceptionQueries,
57: boolean verbose) {
58: StringBuffer failQueries = new StringBuffer();
59: for (int i = 0; i < exceptionQueries.length; i++) {
60: new ExceptionQueryTst(exceptionQueries[i], verbose)
61: .doTest(failQueries);
62: }
63: return failQueries.toString();
64: }
65: }
|