Example usage for org.apache.lucene.analysis TokenStream getAttributeImplsIterator

List of usage examples for org.apache.lucene.analysis TokenStream getAttributeImplsIterator

Introduction

In this page you can find the example usage for org.apache.lucene.analysis TokenStream getAttributeImplsIterator.

Prototype

public final Iterator<AttributeImpl> getAttributeImplsIterator() 

Source Link

Document

Returns a new iterator that iterates all unique Attribute implementations.

Usage

From source file:com.globalsight.ling.tm2.lucene.LuceneUtil.java

License:Apache License

public static org.apache.lucene.analysis.Token getNextToken(TokenStream input) throws IOException {
    org.apache.lucene.analysis.Token token = null;
    if (input.incrementToken()) {
        CharTermAttribute ccc = input.addAttribute(CharTermAttribute.class);
        Iterator<AttributeImpl> attIt = input.getAttributeImplsIterator();

        if (attIt == null || !attIt.hasNext()) {
            return null;
        }/*from w ww.j a v  a 2s.  c om*/

        AttributeImpl att = attIt.next();
        if (att instanceof GSAttributeImpl) {
            token = ((GSAttributeImpl) att).getToken();
        }

        if (token == null && ccc != null && ccc.length() > 0) {
            String ttt = ccc.toString();
            token = new org.apache.lucene.analysis.Token(ttt, 0, ttt.length());
        }
    }

    return token;
}

From source file:org.gridkit.coherence.search.lucene.CapturedTokenStream.java

License:Apache License

public CapturedTokenStream(TokenStream ts, int startPosition, int offset) throws IOException {
    Iterator<AttributeImpl> ai = ts.getAttributeImplsIterator();
    while (ai.hasNext()) {
        AttributeImpl attr = ai.next().clone();
        addAttributeImpl(attr);/* ww w  . ja va  2s.c o  m*/
    }
    tokens = new ArrayList<State>();

    append(ts, startPosition, offset);
}

From source file:org.hibernate.search.indexes.serialization.impl.CopyTokenStream.java

License:Open Source License

private static List<List<AttributeImpl>> fillCache(TokenStream input) throws IOException {
    List<List<AttributeImpl>> results = new ArrayList<List<AttributeImpl>>();
    while (input.incrementToken()) {
        List<AttributeImpl> attrs = new ArrayList<AttributeImpl>();
        results.add(attrs);/*from  ww w .j  a  v a  2  s .co m*/
        Iterator<AttributeImpl> iter = input.getAttributeImplsIterator();
        while (iter.hasNext()) {
            //we need to clone as AttributeImpl instances can be reused across incrementToken() calls
            attrs.add((AttributeImpl) iter.next().clone());
        }
    }
    input.end();
    return results;
}