Save This Page
Home » lucene-3.0.1-src » org.apache.lucene.queryParser.standard.config » [javadoc | source]
    1   package org.apache.lucene.queryParser.standard.config;
    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 org.apache.lucene.document.DateTools;
   21   import org.apache.lucene.queryParser.core.config.FieldConfig;
   22   import org.apache.lucene.queryParser.core.config.FieldConfigListener;
   23   import org.apache.lucene.queryParser.core.config.QueryConfigHandler;
   24   
   25   /**
   26    * This listener listens for every field configuration request and assign a
   27    * {@link DateResolutionAttribute} to the equivalent {@link FieldConfig} based
   28    * on a defined map: fieldName -> DateTools.Resolution stored in
   29    * {@link FieldDateResolutionMapAttribute} in the
   30    * {@link DateResolutionAttribute}.
   31    * 
   32    * @see DateResolutionAttribute
   33    * @see FieldDateResolutionMapAttribute
   34    * @see FieldConfig
   35    * @see FieldConfigListener
   36    */
   37   public class FieldDateResolutionFCListener implements FieldConfigListener {
   38   
   39     private static final long serialVersionUID = -5929802948798314067L;
   40   
   41     private QueryConfigHandler config = null;
   42   
   43     public FieldDateResolutionFCListener(QueryConfigHandler config) {
   44       this.config = config;
   45     }
   46   
   47     public void buildFieldConfig(FieldConfig fieldConfig) {
   48       DateResolutionAttribute fieldDateResAttr = fieldConfig
   49           .addAttribute(DateResolutionAttribute.class);
   50       DateTools.Resolution dateRes = null;
   51   
   52       if (this.config.hasAttribute(FieldDateResolutionMapAttribute.class)) {
   53         FieldDateResolutionMapAttribute dateResMapAttr = this.config
   54             .addAttribute(FieldDateResolutionMapAttribute.class);
   55         dateRes = dateResMapAttr.getFieldDateResolutionMap().get(
   56             fieldConfig.getFieldName().toString());
   57       }
   58   
   59       if (dateRes == null) {
   60   
   61         if (this.config.hasAttribute(DateResolutionAttribute.class)) {
   62           DateResolutionAttribute dateResAttr = this.config
   63               .addAttribute(DateResolutionAttribute.class);
   64           dateRes = dateResAttr.getDateResolution();
   65   
   66         }
   67   
   68       }
   69   
   70       fieldDateResAttr.setDateResolution(dateRes);
   71   
   72     }
   73   
   74   }

Save This Page
Home » lucene-3.0.1-src » org.apache.lucene.queryParser.standard.config » [javadoc | source]