add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / queryparser / src / java / org / apache / lucene / queryParser / standard / StandardQueryParser.java
1 package org.apache.lucene.queryParser.standard;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * 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 java.text.Collator;
21 import java.util.Locale;
22 import java.util.Map;
23 import java.util.TooManyListenersException;
24
25 import org.apache.lucene.analysis.Analyzer;
26 import org.apache.lucene.document.DateTools.Resolution;
27 import org.apache.lucene.document.DateTools;
28 import org.apache.lucene.queryParser.core.QueryNodeException;
29 import org.apache.lucene.queryParser.core.QueryParserHelper;
30 import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
31 import org.apache.lucene.queryParser.standard.builders.StandardQueryTreeBuilder;
32 import org.apache.lucene.queryParser.standard.config.AllowLeadingWildcardAttribute;
33 import org.apache.lucene.queryParser.standard.config.AnalyzerAttribute;
34 import org.apache.lucene.queryParser.standard.config.DateResolutionAttribute;
35 import org.apache.lucene.queryParser.standard.config.DefaultOperatorAttribute;
36 import org.apache.lucene.queryParser.standard.config.DefaultPhraseSlopAttribute;
37 import org.apache.lucene.queryParser.standard.config.FieldBoostMapAttribute;
38 import org.apache.lucene.queryParser.standard.config.FieldDateResolutionMapAttribute;
39 import org.apache.lucene.queryParser.standard.config.FuzzyAttribute;
40 import org.apache.lucene.queryParser.standard.config.FuzzyConfig;
41 import org.apache.lucene.queryParser.standard.config.LocaleAttribute;
42 import org.apache.lucene.queryParser.standard.config.LowercaseExpandedTermsAttribute;
43 import org.apache.lucene.queryParser.standard.config.MultiFieldAttribute;
44 import org.apache.lucene.queryParser.standard.config.MultiTermRewriteMethodAttribute;
45 import org.apache.lucene.queryParser.standard.config.NumericConfig;
46 import org.apache.lucene.queryParser.standard.config.PositionIncrementsAttribute;
47 import org.apache.lucene.queryParser.standard.config.RangeCollatorAttribute;
48 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler;
49 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator;
50 import org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.ConfigurationKeys;
51 import org.apache.lucene.queryParser.standard.nodes.RangeQueryNode;
52 import org.apache.lucene.queryParser.standard.parser.StandardSyntaxParser;
53 import org.apache.lucene.queryParser.standard.processors.StandardQueryNodeProcessorPipeline;
54 import org.apache.lucene.search.FuzzyQuery;
55 import org.apache.lucene.search.MultiTermQuery;
56 import org.apache.lucene.search.Query;
57
58 /**
59  * <p>
60  * This class is a helper that enables users to easily use the Lucene query
61  * parser.
62  * </p>
63  * <p>
64  * To construct a Query object from a query string, use the
65  * {@link #parse(String, String)} method:
66  * <ul>
67  * StandardQueryParser queryParserHelper = new StandardQueryParser(); <br/>
68  * Query query = queryParserHelper.parse("a AND b", "defaultField");
69  * </ul>
70  * <p>
71  * To change any configuration before parsing the query string do, for example:
72  * <p/>
73  * <ul>
74  * // the query config handler returned by {@link StandardQueryParser} is a
75  * {@link StandardQueryConfigHandler} <br/>
76  * queryParserHelper.getQueryConfigHandler().setAnalyzer(new
77  * WhitespaceAnalyzer());
78  * </ul>
79  * <p>
80  * The syntax for query strings is as follows (copied from the old QueryParser
81  * javadoc):
82  * <ul>
83  * A Query is a series of clauses. A clause may be prefixed by:
84  * <ul>
85  * <li>a plus (<code>+</code>) or a minus (<code>-</code>) sign, indicating that
86  * the clause is required or prohibited respectively; or
87  * <li>a term followed by a colon, indicating the field to be searched. This
88  * enables one to construct queries which search multiple fields.
89  * </ul>
90  * 
91  * A clause may be either:
92  * <ul>
93  * <li>a term, indicating all the documents that contain this term; or
94  * <li>a nested query, enclosed in parentheses. Note that this may be used with
95  * a <code>+</code>/<code>-</code> prefix to require any of a set of terms.
96  * </ul>
97  * 
98  * Thus, in BNF, the query grammar is:
99  * 
100  * <pre>
101  *   Query  ::= ( Clause )*
102  *   Clause ::= [&quot;+&quot;, &quot;-&quot;] [&lt;TERM&gt; &quot;:&quot;] ( &lt;TERM&gt; | &quot;(&quot; Query &quot;)&quot; )
103  * </pre>
104  * 
105  * <p>
106  * Examples of appropriately formatted queries can be found in the <a
107  * href="../../../../../../queryparsersyntax.html">query syntax
108  * documentation</a>.
109  * </p>
110  * </ul>
111  * <p>
112  * The text parser used by this helper is a {@link StandardSyntaxParser}.
113  * <p/>
114  * <p>
115  * The query node processor used by this helper is a
116  * {@link StandardQueryNodeProcessorPipeline}.
117  * <p/>
118  * <p>
119  * The builder used by this helper is a {@link StandardQueryTreeBuilder}.
120  * <p/>
121  * 
122  * @see StandardQueryParser
123  * @see StandardQueryConfigHandler
124  * @see StandardSyntaxParser
125  * @see StandardQueryNodeProcessorPipeline
126  * @see StandardQueryTreeBuilder
127  */
128 public class StandardQueryParser extends QueryParserHelper {
129
130   /**
131    * Constructs a {@link StandardQueryParser} object.
132    */
133   public StandardQueryParser() {
134     super(new StandardQueryConfigHandler(), new StandardSyntaxParser(),
135         new StandardQueryNodeProcessorPipeline(null),
136         new StandardQueryTreeBuilder());
137   }
138
139   /**
140    * Constructs a {@link StandardQueryParser} object and sets an
141    * {@link Analyzer} to it. The same as:
142    * 
143    * <ul>
144    * StandardQueryParser qp = new StandardQueryParser();
145    * qp.getQueryConfigHandler().setAnalyzer(analyzer);
146    * </ul>
147    * 
148    * @param analyzer the analyzer to be used by this query parser helper
149    */
150   public StandardQueryParser(Analyzer analyzer) {
151     this();
152
153     this.setAnalyzer(analyzer);
154   }
155
156   @Override
157   public String toString() {
158     return "<StandardQueryParser config=\"" + this.getQueryConfigHandler()
159         + "\"/>";
160   }
161
162   /**
163    * Overrides {@link QueryParserHelper#parse(String, String)} so it casts the
164    * return object to {@link Query}. For more reference about this method, check
165    * {@link QueryParserHelper#parse(String, String)}.
166    * 
167    * @param query the query string
168    * @param defaultField the default field used by the text parser
169    * 
170    * @return the object built from the query
171    * 
172    * @throws QueryNodeException if something wrong happens along the three
173    *         phases
174    */
175   @Override
176   public Query parse(String query, String defaultField)
177       throws QueryNodeException {
178
179     return (Query) super.parse(query, defaultField);
180
181   }
182
183   /**
184    * Gets implicit operator setting, which will be either {@link Operator#AND}
185    * or {@link Operator#OR}.
186    */
187   public StandardQueryConfigHandler.Operator getDefaultOperator() {
188     return getQueryConfigHandler().get(ConfigurationKeys.DEFAULT_OPERATOR);
189   }
190
191   /**
192    * Sets the collator used to determine index term inclusion in ranges for
193    * RangeQuerys.
194    * <p/>
195    * <strong>WARNING:</strong> Setting the rangeCollator to a non-null collator
196    * using this method will cause every single index Term in the Field
197    * referenced by lowerTerm and/or upperTerm to be examined. Depending on the
198    * number of index Terms in this Field, the operation could be very slow.
199    * 
200    * @param collator the collator to use when constructing
201    *        {@link RangeQueryNode}s
202    */
203   public void setRangeCollator(Collator collator) {
204     RangeCollatorAttribute attr = getQueryConfigHandler().getAttribute(
205         RangeCollatorAttribute.class);
206     attr.setDateResolution(collator);
207
208     // uncomment code below when deprecated query parser attributes are removed
209     // getQueryConfigHandler().set(ConfigurationKeys.RANGE_COLLATOR, collator);
210   }
211
212   /**
213    * @return the collator used to determine index term inclusion in ranges for
214    *         RangeQuerys.
215    */
216   public Collator getRangeCollator() {
217     return getQueryConfigHandler().get(ConfigurationKeys.RANGE_COLLATOR);
218   }
219
220   /**
221    * Sets the boolean operator of the QueryParser. In default mode (
222    * {@link Operator#OR}) terms without any modifiers are considered optional:
223    * for example <code>capital of Hungary</code> is equal to
224    * <code>capital OR of OR Hungary</code>.<br/>
225    * In {@link Operator#AND} mode terms are considered to be in conjunction: the
226    * above mentioned query is parsed as <code>capital AND of AND Hungary</code>
227    * 
228    * @deprecated
229    */
230   @Deprecated
231   public void setDefaultOperator(DefaultOperatorAttribute.Operator operator) {
232     DefaultOperatorAttribute attr = getQueryConfigHandler().getAttribute(DefaultOperatorAttribute.class);
233     attr.setOperator(operator);
234   }
235
236   /**
237    * Sets the boolean operator of the QueryParser. In default mode (
238    * {@link Operator#OR}) terms without any modifiers are considered optional:
239    * for example <code>capital of Hungary</code> is equal to
240    * <code>capital OR of OR Hungary</code>.<br/>
241    * In {@link Operator#AND} mode terms are considered to be in conjunction: the
242    * above mentioned query is parsed as <code>capital AND of AND Hungary</code>
243    */
244   public void setDefaultOperator(
245       org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator operator) {
246     
247     DefaultOperatorAttribute.Operator attrOperator;
248     
249     if (operator == org.apache.lucene.queryParser.standard.config.StandardQueryConfigHandler.Operator.AND) {
250       attrOperator = DefaultOperatorAttribute.Operator.AND;
251     } else {
252       attrOperator = DefaultOperatorAttribute.Operator.OR;
253     }
254     
255     setDefaultOperator(attrOperator);
256     
257     // uncomment code below when deprecated query parser attributes are removed
258     // getQueryConfigHandler().set(ConfigurationKeys.DEFAULT_OPERATOR, operator);
259   }
260
261   /**
262    * Set to <code>true</code> to allow leading wildcard characters.
263    * <p>
264    * When set, <code>*</code> or <code>?</code> are allowed as the first
265    * character of a PrefixQuery and WildcardQuery. Note that this can produce
266    * very slow queries on big indexes.
267    * <p>
268    * Default: false.
269    */
270   public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms) {
271     LowercaseExpandedTermsAttribute attr = getQueryConfigHandler()
272         .getAttribute(LowercaseExpandedTermsAttribute.class);
273     attr.setLowercaseExpandedTerms(lowercaseExpandedTerms);
274     // uncomment code below when deprecated query parser attributes are removed
275     // getQueryConfigHandler().set(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS,
276     // lowercaseExpandedTerms);
277   }
278
279   /**
280    * @see #setLowercaseExpandedTerms(boolean)
281    */
282   public boolean getLowercaseExpandedTerms() {
283     Boolean lowercaseExpandedTerms = getQueryConfigHandler().get(
284         ConfigurationKeys.LOWERCASE_EXPANDED_TERMS);
285
286     if (lowercaseExpandedTerms == null) {
287       return true;
288
289     } else {
290       return lowercaseExpandedTerms;
291     }
292
293   }
294
295   /**
296    * Set to <code>true</code> to allow leading wildcard characters.
297    * <p>
298    * When set, <code>*</code> or <code>?</code> are allowed as the first
299    * character of a PrefixQuery and WildcardQuery. Note that this can produce
300    * very slow queries on big indexes.
301    * <p>
302    * Default: false.
303    */
304   public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
305     AllowLeadingWildcardAttribute attr = getQueryConfigHandler().getAttribute(
306         AllowLeadingWildcardAttribute.class);
307     attr.setAllowLeadingWildcard(allowLeadingWildcard);
308     // uncomment code below when deprecated query parser attributes are removed
309     // getQueryConfigHandler().set(ConfigurationKeys.ALLOW_LEADING_WILDCARD,
310     // allowLeadingWildcard);
311   }
312
313   /**
314    * Set to <code>true</code> to enable position increments in result query.
315    * <p>
316    * When set, result phrase and multi-phrase queries will be aware of position
317    * increments. Useful when e.g. a StopFilter increases the position increment
318    * of the token that follows an omitted token.
319    * <p>
320    * Default: false.
321    */
322   public void setEnablePositionIncrements(boolean enabled) {
323     PositionIncrementsAttribute attr = getQueryConfigHandler().getAttribute(
324         PositionIncrementsAttribute.class);
325     attr.setPositionIncrementsEnabled(enabled);
326     // uncomment code below when deprecated query parser attributes are removed
327     // getQueryConfigHandler().set(ConfigurationKeys.ENABLE_POSITION_INCREMENTS,
328     // enabled);
329   }
330
331   /**
332    * @see #setEnablePositionIncrements(boolean)
333    */
334   public boolean getEnablePositionIncrements() {
335     Boolean enablePositionsIncrements = getQueryConfigHandler().get(
336         ConfigurationKeys.ENABLE_POSITION_INCREMENTS);
337
338     if (enablePositionsIncrements == null) {
339       return false;
340
341     } else {
342       return enablePositionsIncrements;
343     }
344
345   }
346
347   /**
348    * By default, it uses
349    * {@link MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT} when creating a
350    * prefix, wildcard and range queries. This implementation is generally
351    * preferable because it a) Runs faster b) Does not have the scarcity of terms
352    * unduly influence score c) avoids any {@link TooManyListenersException}
353    * exception. However, if your application really needs to use the
354    * old-fashioned boolean queries expansion rewriting and the above points are
355    * not relevant then use this change the rewrite method.
356    */
357   public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method) {
358     MultiTermRewriteMethodAttribute attr = getQueryConfigHandler()
359         .getAttribute(MultiTermRewriteMethodAttribute.class);
360     attr.setMultiTermRewriteMethod(method);
361     // uncomment code below when deprecated query parser attributes are removed
362     // getQueryConfigHandler().set(ConfigurationKeys.MULTI_TERM_REWRITE_METHOD,
363     // method);
364   }
365
366   /**
367    * @see #setMultiTermRewriteMethod(org.apache.lucene.search.MultiTermQuery.RewriteMethod)
368    */
369   public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod() {
370     return getQueryConfigHandler().get(
371         ConfigurationKeys.MULTI_TERM_REWRITE_METHOD);
372   }
373
374   /**
375    * Set the fields a query should be expanded to when the field is
376    * <code>null</code>
377    * 
378    * @param fields the fields used to expand the query
379    */
380   public void setMultiFields(CharSequence[] fields) {
381
382     if (fields == null) {
383       fields = new CharSequence[0];
384     }
385
386     MultiFieldAttribute attr = getQueryConfigHandler().addAttribute(
387         MultiFieldAttribute.class);
388     attr.setFields(fields);
389     // uncomment code below when deprecated query parser attributes are removed
390     // getQueryConfigHandler().set(ConfigurationKeys.MULTI_FIELDS, fields);
391
392   }
393
394   /**
395    * Returns the fields used to expand the query when the field for a certain
396    * query is <code>null</code>
397    * 
398    * @param fields the fields used to expand the query
399    */
400   public void getMultiFields(CharSequence[] fields) {
401     getQueryConfigHandler().get(ConfigurationKeys.MULTI_FIELDS);
402   }
403
404   /**
405    * Set the prefix length for fuzzy queries. Default is 0.
406    * 
407    * @param fuzzyPrefixLength The fuzzyPrefixLength to set.
408    */
409   public void setFuzzyPrefixLength(int fuzzyPrefixLength) {
410     FuzzyAttribute attr = getQueryConfigHandler().addAttribute(
411         FuzzyAttribute.class);
412     attr.setPrefixLength(fuzzyPrefixLength);
413
414     // uncomment code below when deprecated query parser attributes are removed
415     /*
416      * QueryConfigHandler config = getQueryConfigHandler(); FuzzyConfig
417      * fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG);
418      * 
419      * if (fuzzyConfig == null) { fuzzyConfig = new FuzzyConfig();
420      * config.set(ConfigurationKeys.FUZZY_CONFIG, fuzzyConfig); }
421      * 
422      * fuzzyConfig.setPrefixLength(fuzzyPrefixLength);
423      */
424   }
425
426   public void setNumericConfigMap(Map<String, NumericConfig> numericConfigMap) {
427     getQueryConfigHandler().set(ConfigurationKeys.NUMERIC_CONFIG_MAP,
428         numericConfigMap);
429   }
430
431   public Map<String, NumericConfig> getNumericConfigMap() {
432     return getQueryConfigHandler().get(ConfigurationKeys.NUMERIC_CONFIG_MAP);
433   }
434
435   /**
436    * Set locale used by date range parsing.
437    */
438   public void setLocale(Locale locale) {
439     LocaleAttribute attr = getQueryConfigHandler().addAttribute(
440         LocaleAttribute.class);
441     attr.setLocale(locale);
442     // uncomment code below when deprecated query parser attributes are removed
443     // getQueryConfigHandler().set(ConfigurationKeys.LOCALE, locale);
444   }
445
446   /**
447    * Returns current locale, allowing access by subclasses.
448    */
449   public Locale getLocale() {
450     return getQueryConfigHandler().get(ConfigurationKeys.LOCALE);
451   }
452
453   /**
454    * Sets the default slop for phrases. If zero, then exact phrase matches are
455    * required. Default value is zero.
456    * 
457    * @deprecated renamed to {@link #setPhraseSlop(int)}
458    */
459   @Deprecated
460   public void setDefaultPhraseSlop(int defaultPhraseSlop) {
461     setPhraseSlop(defaultPhraseSlop);
462   }
463
464   /**
465    * Sets the default slop for phrases. If zero, then exact phrase matches are
466    * required. Default value is zero.
467    */
468   public void setPhraseSlop(int defaultPhraseSlop) {
469     DefaultPhraseSlopAttribute attr = getQueryConfigHandler().addAttribute(
470         DefaultPhraseSlopAttribute.class);
471     attr.setDefaultPhraseSlop(defaultPhraseSlop);
472     // uncomment code below when deprecated query parser attributes are removed
473     // getQueryConfigHandler().set(ConfigurationKeys.PHRASE_SLOP,
474     // defaultPhraseSlop);
475   }
476
477   public void setAnalyzer(Analyzer analyzer) {
478     AnalyzerAttribute attr = getQueryConfigHandler().getAttribute(
479         AnalyzerAttribute.class);
480     attr.setAnalyzer(analyzer);
481     // uncomment code below when deprecated query parser attributes are removed
482     // getQueryConfigHandler().set(ConfigurationKeys.ANALYZER, analyzer);
483   }
484
485   public Analyzer getAnalyzer() {
486     return getQueryConfigHandler().get(ConfigurationKeys.ANALYZER);
487   }
488
489   /**
490    * @see #setAllowLeadingWildcard(boolean)
491    */
492   public boolean getAllowLeadingWildcard() {
493     Boolean allowLeadingWildcard = getQueryConfigHandler().get(
494         ConfigurationKeys.ALLOW_LEADING_WILDCARD);
495
496     if (allowLeadingWildcard == null) {
497       return false;
498
499     } else {
500       return allowLeadingWildcard;
501     }
502   }
503
504   /**
505    * Get the minimal similarity for fuzzy queries.
506    */
507   public float getFuzzyMinSim() {
508     FuzzyConfig fuzzyConfig = getQueryConfigHandler().get(
509         ConfigurationKeys.FUZZY_CONFIG);
510
511     if (fuzzyConfig == null) {
512       return FuzzyQuery.defaultMinSimilarity;
513     } else {
514       return fuzzyConfig.getMinSimilarity();
515     }
516   }
517
518   /**
519    * Get the prefix length for fuzzy queries.
520    * 
521    * @return Returns the fuzzyPrefixLength.
522    */
523   public int getFuzzyPrefixLength() {
524     FuzzyConfig fuzzyConfig = getQueryConfigHandler().get(
525         ConfigurationKeys.FUZZY_CONFIG);
526
527     if (fuzzyConfig == null) {
528       return FuzzyQuery.defaultPrefixLength;
529     } else {
530       return fuzzyConfig.getPrefixLength();
531     }
532   }
533
534   /**
535    * Gets the default slop for phrases.
536    */
537   public int getPhraseSlop() {
538     Integer phraseSlop = getQueryConfigHandler().get(
539         ConfigurationKeys.PHRASE_SLOP);
540
541     if (phraseSlop == null) {
542       return 0;
543
544     } else {
545       return phraseSlop;
546     }
547   }
548
549   /**
550    * Set the minimum similarity for fuzzy queries. Default is defined on
551    * {@link FuzzyQuery#defaultMinSimilarity}.
552    */
553   public void setFuzzyMinSim(float fuzzyMinSim) {
554     FuzzyAttribute attr = getQueryConfigHandler().addAttribute(
555         FuzzyAttribute.class);
556     attr.setFuzzyMinSimilarity(fuzzyMinSim);
557     // uncomment code below when deprecated query parser attributes are removed
558     /*
559      * QueryConfigHandler config = getQueryConfigHandler(); FuzzyConfig
560      * fuzzyConfig = config.get(ConfigurationKeys.FUZZY_CONFIG);
561      * 
562      * if (fuzzyConfig == null) { fuzzyConfig = new FuzzyConfig();
563      * config.set(ConfigurationKeys.FUZZY_CONFIG, fuzzyConfig); }
564      * 
565      * fuzzyConfig.setMinSimilarity(fuzzyMinSim);
566      */
567   }
568
569   /**
570    * Sets the boost used for each field.
571    * 
572    * @param boosts a collection that maps a field to its boost
573    */
574   public void setFieldsBoost(Map<String, Float> boosts) {
575     FieldBoostMapAttribute attr = getQueryConfigHandler().addAttribute(
576         FieldBoostMapAttribute.class);
577     attr.setFieldBoostMap(boosts);
578     // uncomment code below when deprecated query parser attributes are removed
579     // getQueryConfigHandler().set(ConfigurationKeys.FIELD_BOOST_MAP, boosts);
580   }
581
582   /**
583    * Returns the field to boost map used to set boost for each field.
584    * 
585    * @return the field to boost map
586    */
587   public Map<String, Float> getFieldsBoost() {
588     return getQueryConfigHandler().get(ConfigurationKeys.FIELD_BOOST_MAP);
589   }
590
591   /**
592    * Sets the default {@link Resolution} used for certain field when no
593    * {@link Resolution} is defined for this field.
594    * 
595    * @param dateResolution the default {@link Resolution}
596    */
597   public void setDateResolution(DateTools.Resolution dateResolution) {
598     DateResolutionAttribute attr = getQueryConfigHandler().addAttribute(
599         DateResolutionAttribute.class);
600     attr.setDateResolution(dateResolution);
601     // uncomment code below when deprecated query parser attributes are removed
602     // getQueryConfigHandler().set(ConfigurationKeys.DATE_RESOLUTION,
603     // dateResolution);
604   }
605
606   /**
607    * Returns the default {@link Resolution} used for certain field when no
608    * {@link Resolution} is defined for this field.
609    * 
610    * @return the default {@link Resolution}
611    */
612   public DateTools.Resolution getDateResolution() {
613     return getQueryConfigHandler().get(ConfigurationKeys.DATE_RESOLUTION);
614   }
615
616   /**
617    * Sets the {@link Resolution} used for each field
618    * 
619    * @param dateRes a collection that maps a field to its {@link Resolution}
620    * 
621    * @deprecated this method was renamed to {@link #setDateResolutionMap(Map)}
622    */
623   @Deprecated
624   public void setDateResolution(Map<CharSequence, DateTools.Resolution> dateRes) {
625     setDateResolutionMap(dateRes);
626   }
627
628   /**
629    * Returns the field to {@link Resolution} map used to normalize each date
630    * field.
631    * 
632    * @return the field to {@link Resolution} map
633    */
634   public Map<CharSequence, DateTools.Resolution> getDateResolutionMap() {
635     return getQueryConfigHandler().get(
636         ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP);
637   }
638
639   /**
640    * Sets the {@link Resolution} used for each field
641    * 
642    * @param dateRes a collection that maps a field to its {@link Resolution}
643    */
644   public void setDateResolutionMap(
645       Map<CharSequence, DateTools.Resolution> dateRes) {
646     FieldDateResolutionMapAttribute attr = getQueryConfigHandler()
647         .addAttribute(FieldDateResolutionMapAttribute.class);
648     attr.setFieldDateResolutionMap(dateRes);
649     // uncomment code below when deprecated query parser attributes are removed
650     // getQueryConfigHandler().set(ConfigurationKeys.FIELD_DATE_RESOLUTION_MAP,
651     // dateRes);
652   }
653
654 }