Java Code Examples for org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl#setType()

The following examples show how to use org.apache.lucene.analysis.tokenattributes.PackedTokenAttributeImpl#setType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MLTokenDuplicator.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Iterator<PackedTokenAttributeImpl> buildIterator() throws IOException
{
    // TODO: use incrementToken() somehow?
    if(!done && source.incrementToken())
    {
        CharTermAttribute cta = source.getAttribute(CharTermAttribute.class);
        OffsetAttribute offsetAtt = source.getAttribute(OffsetAttribute.class);
        TypeAttribute typeAtt = null;
        if(source.hasAttribute(TypeAttribute.class))
        {
            typeAtt = source.getAttribute(TypeAttribute.class);
        }
        PositionIncrementAttribute posIncAtt = null;
        if(source.hasAttribute(PositionIncrementAttribute.class))
        {
            posIncAtt = source.getAttribute(PositionIncrementAttribute.class);
        }
        PackedTokenAttributeImpl token = new PackedTokenAttributeImpl();
        token.setEmpty().append(new String(cta.buffer()), 0, cta.length());
        token.setOffset(offsetAtt.startOffset(), offsetAtt.endOffset());
        if(typeAtt != null)
        {
            token.setType(typeAtt.type());
        }
        if(posIncAtt != null)
        {
            token.setPositionIncrement(posIncAtt.getPositionIncrement());
        }
        return buildIterator(token);
    }
    else
    {
        done = true;
        return buildIterator(null);
    }
    

}
 
Example 2
Source File: MLTokenDuplicator.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Iterator<PackedTokenAttributeImpl> buildIterator(PackedTokenAttributeImpl token)
{
    if (token == null)
    {
        return null;
    }

    ArrayList<PackedTokenAttributeImpl> tokens = new ArrayList<PackedTokenAttributeImpl>(prefixes.size());
    for (String prefix : prefixes)
    {   
        
    	PackedTokenAttributeImpl newToken = new PackedTokenAttributeImpl();
    	newToken.setEmpty().append(prefix + termText(token));
    	newToken.setOffset(token.startOffset(), token.endOffset());
        newToken.setType(token.type());
        if (tokens.size() == 0)
        {
            newToken.setPositionIncrement(token.getPositionIncrement());
        }
        else
        {
            newToken.setPositionIncrement(0);
        }
        tokens.add(newToken);
    }
    return tokens.iterator();

}
 
Example 3
Source File: CutLetterDigitFilter.java    From mmseg4j-solr with Apache License 2.0 5 votes vote down vote up
private void addToken(PackedTokenAttributeImpl oriToken, int termBufferOffset, int termBufferLength, byte type) {
	PackedTokenAttributeImpl token = TokenUtils.subToken(oriToken, termBufferOffset, termBufferLength);

	if(type == Character.DECIMAL_DIGIT_NUMBER) {
		token.setType(Word.TYPE_DIGIT);
	} else {
		token.setType(Word.TYPE_LETTER);
	}

	tokenQueue.offer(token);
}