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 java.util.List;
   21   
   22   import org.apache.lucene.queryParser.core.parser.EscapeQuerySyntax;
   23   
   24   /**
   25    * A {@link TokenizedPhraseQueryNode} represents a node created by a code that
   26    * tokenizes/lemmatizes/analyzes.
   27    */
   28   public class TokenizedPhraseQueryNode extends QueryNodeImpl implements
   29       FieldableNode {
   30   
   31     private static final long serialVersionUID = -7185108320787917541L;
   32   
   33     public TokenizedPhraseQueryNode() {
   34       setLeaf(false);
   35       allocate();
   36     }
   37   
   38     @Override
   39     public String toString() {
   40       if (getChildren() == null || getChildren().size() == 0)
   41         return "<tokenizedphrase/>";
   42       StringBuilder sb = new StringBuilder();
   43       sb.append("<tokenizedtphrase>");
   44       for (QueryNode child : getChildren()) {
   45         sb.append("\n");
   46         sb.append(child.toString());
   47       }
   48       sb.append("\n</tokenizedphrase>");
   49       return sb.toString();
   50     }
   51   
   52     // This text representation is not re-parseable
   53     public CharSequence toQueryString(EscapeQuerySyntax escapeSyntaxParser) {
   54       if (getChildren() == null || getChildren().size() == 0)
   55         return "";
   56   
   57       StringBuilder sb = new StringBuilder();
   58       String filler = "";
   59       for (QueryNode child : getChildren()) {
   60         sb.append(filler).append(child.toQueryString(escapeSyntaxParser));
   61         filler = ",";
   62       }
   63   
   64       return "[TP[" + sb.toString() + "]]";
   65     }
   66   
   67     @Override
   68     public QueryNode cloneTree() throws CloneNotSupportedException {
   69       TokenizedPhraseQueryNode clone = (TokenizedPhraseQueryNode) super
   70           .cloneTree();
   71   
   72       // nothing to do
   73   
   74       return clone;
   75     }
   76   
   77     public CharSequence getField() {
   78       List<QueryNode> children = getChildren();
   79   
   80       if (children == null || children.size() == 0) {
   81         return null;
   82   
   83       } else {
   84         return ((FieldableNode) children.get(0)).getField();
   85       }
   86   
   87     }
   88   
   89     public void setField(CharSequence fieldName) {
   90       List<QueryNode> children = getChildren();
   91   
   92       if (children != null) {
   93   
   94         for (QueryNode child : getChildren()) {
   95   
   96           if (child instanceof FieldableNode) {
   97             ((FieldableNode) child).setField(fieldName);
   98           }
   99   
  100         }
  101   
  102       }
  103   
  104     }
  105   
  106   } // end class MultitermQueryNode

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