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.messages.MessageImpl;
   21   import org.apache.lucene.queryParser.core.QueryNodeError;
   22   import org.apache.lucene.queryParser.core.QueryNodeException;
   23   import org.apache.lucene.queryParser.core.QueryNodeParseException;
   24   import org.apache.lucene.queryParser.core.messages.QueryParserMessages;
   25   import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
   26   
   27   public class PhraseSlopQueryNode extends QueryNodeImpl implements FieldableNode {
   28   
   29     private static final long serialVersionUID = 0L;
   30   
   31     private int value = 0;
   32   
   33     /**
   34      * @throws QueryNodeException
   35      * @throws QueryNodeParseException
   36      * @exception QueryNodeParseException
   37      *              throw in overridden method to disallow
   38      */
   39     public PhraseSlopQueryNode(QueryNode query, int value)
   40         throws QueryNodeException {
   41       if (query == null) {
   42         throw new QueryNodeError(new MessageImpl(
   43             QueryParserMessages.NODE_ACTION_NOT_SUPPORTED, "query", "null"));
   44       }
   45   
   46       this.value = value;
   47       setLeaf(false);
   48       allocate();
   49       add(query);
   50     }
   51   
   52     public QueryNode getChild() {
   53       return getChildren().get(0);
   54     }
   55   
   56     public int getValue() {
   57       return this.value;
   58     }
   59   
   60     private CharSequence getValueString() {
   61       Float f = Float.valueOf(this.value);
   62       if (f == f.longValue())
   63         return "" + f.longValue();
   64       else
   65         return "" + f;
   66   
   67     }
   68   
   69     @Override
   70     public String toString() {
   71       return "<phraseslop value='" + getValueString() + "'>" + "\n"
   72           + getChild().toString() + "\n</phraseslop>";
   73     }
   74   
   75     public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
   76       if (getChild() == null)
   77         return "";
   78       return getChild().toQueryString(escapeSyntaxParser) + "~"
   79           + getValueString();
   80     }
   81   
   82     @Override
   83     public QueryNode cloneTree() throws CloneNotSupportedException {
   84       PhraseSlopQueryNode clone = (PhraseSlopQueryNode) super.cloneTree();
   85   
   86       clone.value = this.value;
   87   
   88       return clone;
   89     }
   90   
   91     public CharSequence getField() {
   92       QueryNode child = getChild();
   93   
   94       if (child instanceof FieldableNode) {
   95         return ((FieldableNode) child).getField();
   96       }
   97   
   98       return null;
   99   
  100     }
  101   
  102     public void setField(CharSequence fieldName) {
  103       QueryNode child = getChild();
  104   
  105       if (child instanceof FieldableNode) {
  106         ((FieldableNode) child).setField(fieldName);
  107       }
  108   
  109     }
  110   
  111   }

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