//# 0 errors, 26 messages
//#
/*
    //#IndexUtil.java:1:1: class: org.apache.roller.weblogger.business.search.IndexUtil
    //#IndexUtil.java:1:1: method: org.apache.roller.weblogger.business.search.IndexUtil.org.apache.roller.weblogger.business.search.IndexUtil__static_init
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
/* Created on Jul 20, 2003 */
package org.apache.roller.weblogger.business.search;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.index.Term;
import org.apache.roller.weblogger.business.search.IndexManagerImpl;

import java.io.IOException;
import java.io.StringReader;

/**
 * Class containing helper methods.
 * @author Mindaugas Idzelis (min@idzelis.com)
 */
public class IndexUtil {
    //#IndexUtil.java:34: method: void org.apache.roller.weblogger.business.search.IndexUtil.org.apache.roller.weblogger.business.search.IndexUtil()
    //#IndexUtil.java:34: end of method: void org.apache.roller.weblogger.business.search.IndexUtil.org.apache.roller.weblogger.business.search.IndexUtil()
    
    /**
     * Create a lucene term from the first token of the input string.
     *
     * @param field The lucene document field to create a term with
     * @param input The input you wish to convert into a term
     * @return Lucene search term
     */
    public static final Term getTerm(String field, String input) {
        if (input==null || field==null) return null;
    //#IndexUtil.java:44: method: Term org.apache.roller.weblogger.business.search.IndexUtil.getTerm(String, String)
    //#input(Term getTerm(String, String)): field
    //#input(Term getTerm(String, String)): input
    //#output(Term getTerm(String, String)): new Term(getTerm#2) num objects
    //#output(Term getTerm(String, String)): return_value
    //#new obj(Term getTerm(String, String)): new Term(getTerm#2)
    //#presumption(Term getTerm(String, String)): getAnalyzer(...)@45 init'ed
    //#presumption(Term getTerm(String, String)): org.apache.lucene.analysis.Analyzer:tokenStream(...)@46 != null
    //#post(Term getTerm(String, String)): return_value in Addr_Set{null,&new Term(getTerm#2)}
    //#post(Term getTerm(String, String)): new Term(getTerm#2) num objects <= 1
    //#unanalyzed(Term getTerm(String, String)): Effects-of-calling:org.apache.lucene.analysis.standard.StandardAnalyzer
    //#test_vector(Term getTerm(String, String)): field: Inverse{null}, Addr_Set{null}
    //#test_vector(Term getTerm(String, String)): input: Addr_Set{null}, Inverse{null}
        Analyzer analyer = IndexManagerImpl.getAnalyzer();
        TokenStream tokens = analyer.tokenStream(field,
    //#IndexUtil.java:46: Warning: method not available
    //#    -- call on TokenStream org.apache.lucene.analysis.Analyzer:tokenStream(String, Reader)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.search.IndexUtil
    //#    method: Term getTerm(String, String)
    //#    unanalyzed callee: TokenStream org.apache.lucene.analysis.Analyzer:tokenStream(String, Reader)
                new StringReader(input));
        
        Token token = null;
        Term term = null;
        try {
            token = tokens.next();
    //#IndexUtil.java:52: Warning: method not available
    //#    -- call on Token org.apache.lucene.analysis.TokenStream:next()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.search.IndexUtil
    //#    method: Term getTerm(String, String)
    //#    unanalyzed callee: Token org.apache.lucene.analysis.TokenStream:next()
        } catch (IOException e) {}
        if (token!=null) {
            String termt = token.termText();
    //#IndexUtil.java:55: Warning: method not available
    //#    -- call on String org.apache.lucene.analysis.Token:termText()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.search.IndexUtil
    //#    method: Term getTerm(String, String)
    //#    unanalyzed callee: String org.apache.lucene.analysis.Token:termText()
            term = new Term(field,termt);
    //#IndexUtil.java:56: Warning: method not available
    //#    -- call on void org.apache.lucene.index.Term(String, String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.business.search.IndexUtil
    //#    method: Term getTerm(String, String)
    //#    unanalyzed callee: void org.apache.lucene.index.Term(String, String)
        }
        return term;
    //#IndexUtil.java:58: end of method: Term org.apache.roller.weblogger.business.search.IndexUtil.getTerm(String, String)
    }
    
}
    //#output(org.apache.roller.weblogger.business.search.IndexUtil__static_init): __Descendant_Table[org/apache/roller/weblogger/business/search/IndexUtil]
    //#post(org.apache.roller.weblogger.business.search.IndexUtil__static_init): __Descendant_Table[org/apache/roller/weblogger/business/search/IndexUtil] == &__Dispatch_Table
    //#IndexUtil.java:: end of method: org.apache.roller.weblogger.business.search.IndexUtil.org.apache.roller.weblogger.business.search.IndexUtil__static_init
    //#IndexUtil.java:: end of class: org.apache.roller.weblogger.business.search.IndexUtil
