View Javadoc

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.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( final Field field, final 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 query
51       * @param type
52       * @return
53       * @throws ParseException if query parsing is unsuccessful.
54       */
55      Query constructQuery( Field field, SearchExpression expression )
56          throws ParseException;
57  
58      /**
59       * Constructs query by parsing the query string, using field as default field. This method should be use to
60       * construct queries (single term or phrase queries) against <b>single field</b>.
61       * 
62       * @param field
63       * @param query
64       * @param type
65       * @return
66       * @throws ParseException if query parsing is unsuccessful.
67       * @deprecated Use {@link #constructQuery(Field, SearchExpression)} instead.
68       */
69      Query constructQuery( Field field, String query, SearchType type )
70          throws ParseException;
71  
72      /**
73       * Deprecated. Avoid it's use! Constructs query against <b>single</b> field, using it's "best effort" approach to
74       * perform parsing, but letting caller to apply it's (usually wrong) knowledge about how field is indexed.
75       * 
76       * @param field
77       * @param query
78       * @return query if successfully parsed, or null.
79       * @deprecated Use {@link #constructQuery(Field, SearchExpression)} instead.
80       */
81      Query constructQuery( String field, String query );
82  
83  }