Example usage for org.apache.lucene.document Field tokenStream

List of usage examples for org.apache.lucene.document Field tokenStream

Introduction

In this page you can find the example usage for org.apache.lucene.document Field tokenStream.

Prototype

TokenStream tokenStream

To view the source code for org.apache.lucene.document Field tokenStream.

Click Source Link

Document

Pre-analyzed tokenStream for indexed fields; this is separate from fieldsData because you are allowed to have both; eg maybe field has a String value but you customize how it's tokenized

Usage

From source file:edu.utsa.sifter.DocMaker.java

License:Apache License

public static boolean addBodyField(final Document doc, final String body, final Analyzer analyzer,
        boolean testEmpty) throws IOException {
    final Field f = new Field("body", body, BodyOptions);
    if (testEmpty) {
        // System.out.println("testing if doc has empty body");
        final TokenStream toks = f.tokenStream(analyzer);
        toks.reset();//www.ja  v a 2 s  . c  o  m
        if (!toks.incrementToken()) {
            // System.out.println("empty body, won't index");
            toks.close();
            return false;
        }
    }
    doc.add(new Field("body", body, BodyOptions));
    doc.add(new LongField("body-len", body.length(), Field.Store.YES));
    return true;
}