File Source: IndexUtil.java

         /* 
    P/P   *  Method: org.apache.roller.weblogger.business.search.IndexUtil__static_init
          */
     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   *  contributor license agreements.  The ASF licenses this file to You
     4   * under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.  For additional information regarding
    15   * copyright in this work, please see the NOTICE file in the top level
    16   * directory of this distribution.
    17   */
    18  /* Created on Jul 20, 2003 */
    19  package org.apache.roller.weblogger.business.search;
    20  
    21  import org.apache.lucene.analysis.Analyzer;
    22  import org.apache.lucene.analysis.Token;
    23  import org.apache.lucene.analysis.TokenStream;
    24  import org.apache.lucene.index.Term;
    25  import org.apache.roller.weblogger.business.search.IndexManagerImpl;
    26  
    27  import java.io.IOException;
    28  import java.io.StringReader;
    29  
    30  /**
    31   * Class containing helper methods.
    32   * @author Mindaugas Idzelis (min@idzelis.com)
    33   */
         /* 
    P/P   *  Method: void org.apache.roller.weblogger.business.search.IndexUtil()
          */
    34  public class IndexUtil {
    35      
    36      /**
    37       * Create a lucene term from the first token of the input string.
    38       *
    39       * @param field The lucene document field to create a term with
    40       * @param input The input you wish to convert into a term
    41       * @return Lucene search term
    42       */
    43      public static final Term getTerm(String field, String input) {
                 /* 
    P/P           *  Method: Term getTerm(String, String)
                  * 
                  *  Presumptions:
                  *    getAnalyzer(...)@45 init'ed
                  *    org.apache.lucene.analysis.Analyzer:tokenStream(...)@46 != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{null,&new Term(getTerm#2)}
                  *    new Term(getTerm#2) num objects <= 1
                  * 
                  *  Test Vectors:
                  *    field: Inverse{null}, Addr_Set{null}
                  *    input: Addr_Set{null}, Inverse{null}
                  */
    44          if (input==null || field==null) return null;
    45          Analyzer analyer = IndexManagerImpl.getAnalyzer();
    46          TokenStream tokens = analyer.tokenStream(field,
    47                  new StringReader(input));
    48          
    49          Token token = null;
    50          Term term = null;
    51          try {
    52              token = tokens.next();
    53          } catch (IOException e) {}
    54          if (token!=null) {
    55              String termt = token.termText();
    56              term = new Term(field,termt);
    57          }
    58          return term;
    59      }
    60      
    61  }








SofCheck Inspector Build Version : 2.18479
IndexUtil.java 2009-Jan-02 14:25:38
IndexUtil.class 2009-Sep-04 03:12:31