1 package org.apache.maven.index;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.lucene.queryparser.classic.ParseException;
23 import org.apache.lucene.search.Query;
24 import org.apache.maven.index.expr.SearchExpression;
25
26 /**
27 * A component the creates Lucene Queries from "human written" queries, but also helps client applications to assemble
28 * proper queries for fields they want to search.
29 *
30 * @author Tamas Cservenak
31 */
32 public interface QueryCreator
33 {
34 String ROLE = QueryCreator.class.getName();
35
36 /**
37 * Performs a selection of the appropriate IndexerField belonging to proper Field.
38 *
39 * @param field
40 * @param type
41 * @return
42 */
43 IndexerField selectIndexerField( Field field, SearchType type );
44
45 /**
46 * Constructs query by parsing the query string, using field as default field. This method should be use to
47 * construct queries (single term or phrase queries) against <b>single field</b>.
48 *
49 * @param field
50 * @param expression
51 * @return
52 * @throws ParseException if query parsing is unsuccessful.
53 */
54 Query constructQuery( Field field, SearchExpression expression )
55 throws ParseException;
56
57 /**
58 * Constructs query by parsing the query string, using field as default field. This method should be use to
59 * construct queries (single term or phrase queries) against <b>single field</b>.
60 *
61 * @param field
62 * @param query
63 * @param type
64 * @return
65 * @throws ParseException if query parsing is unsuccessful.
66 * @deprecated Use {@link #constructQuery(Field, SearchExpression)} instead.
67 */
68 Query constructQuery( Field field, String query, SearchType type )
69 throws ParseException;
70
71 /**
72 * Deprecated. Avoid it's use! Constructs query against <b>single</b> field, using it's "best effort" approach to
73 * perform parsing, but letting caller to apply it's (usually wrong) knowledge about how field is indexed.
74 *
75 * @param field
76 * @param query
77 * @return query if successfully parsed, or null.
78 * @deprecated Use {@link #constructQuery(Field, SearchExpression)} instead.
79 */
80 Query constructQuery( String field, String query );
81
82 }