Save This Page
Home » lucene-3.0.1-src » org.apache.lucene.queryParser.core.nodes » [javadoc | source]
    1   package org.apache.lucene.queryParser.core.nodes;
    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.queryParser.core.parser.EscapeQuerySyntax;
   21   
   22   /**
   23    * A {@link ParametricQueryNode} represents LE, LT, GE, GT, EQ, NE query.
   24    * Example: date >= "2009-10-10" OR price = 200
   25    */
   26   public class ParametricQueryNode extends FieldQueryNode {
   27   
   28     private static final long serialVersionUID = -5770038129741218116L;
   29   
   30     private CompareOperator operator;
   31   
   32     public enum CompareOperator {
   33       LE { 
   34         @Override
   35         public String toString() { return "<="; }
   36       },
   37       LT {
   38         @Override
   39         public String toString() { return "<";  }
   40       },
   41       GE {
   42         @Override
   43         public String toString() { return ">="; }
   44       },
   45       GT {
   46         @Override
   47         public String toString() { return ">";  }
   48       },
   49       EQ {
   50         @Override
   51         public String toString() { return "=";  }
   52       },
   53       NE {
   54         @Override
   55         public String toString() { return "!="; }
   56       };
   57     }
   58   
   59     /**
   60      * @param field
   61      *          - field name
   62      * @param comp
   63      *          - CompareOperator
   64      * @param value
   65      *          - text value
   66      * @param begin
   67      *          - position in the query string
   68      * @param end
   69      *          - position in the query string
   70      */
   71     public ParametricQueryNode(CharSequence field, CompareOperator comp,
   72         CharSequence value, int begin, int end) {
   73       super(field, value, begin, end);
   74       this.operator = comp;
   75       setLeaf(true);
   76     }
   77   
   78     public CharSequence getOperand() {
   79       return getText();
   80     }
   81   
   82     @Override
   83     public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
   84       return this.field + "" + this.operator.toString() + "\"" + this.text + "\"";
   85     }
   86   
   87     @Override
   88     public String toString() {
   89       return "<parametric field='" + this.field + "' operator='"
   90           + this.operator.toString() + "' text='" + this.text + "'/>";
   91     }
   92   
   93     @Override
   94     public ParametricQueryNode cloneTree() throws CloneNotSupportedException {
   95       ParametricQueryNode clone = (ParametricQueryNode) super.cloneTree();
   96   
   97       clone.operator = this.operator;
   98   
   99       return clone;
  100     }
  101   
  102     /**
  103      * @return the operator
  104      */
  105     public CompareOperator getOperator() {
  106       return this.operator;
  107     }
  108   }

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