/** * Iterates over the given token stream and adds the resulting terms to the index; * Equivalent to adding a tokenized, indexed, termVectorStored, unstored, * Lucene {@link org.apache.lucene.document.Field}. * Finally closes the token stream. Note that untokenized keywords can be added with this method via * {@link #keywordTokenStream(Collection)}, the Lucene <code>KeywordTokenizer</code> or similar utilities. * * * @param fieldName * a name to be associated with the text * @param tokenStream * the token stream to retrieve tokens from. It's guaranteed to be closed no matter what. * @param positionIncrementGap * the position increment gap if fields with the same name are added more than once * @param offsetGap * the offset gap if fields with the same name are added more than once */ public void addField(String fieldName, TokenStream tokenStream, int positionIncrementGap, int offsetGap) { Info info = getInfo(fieldName, defaultFieldType); storeTerms(info, tokenStream, positionIncrementGap, offsetGap); }
/** * Convenience method; Tokenizes the given field text and adds the resulting * terms to the index; Equivalent to adding an indexed non-keyword Lucene * {@link org.apache.lucene.document.Field} that is tokenized, not stored, * termVectorStored with positions (or termVectorStored with positions and offsets), * * @param fieldName * a name to be associated with the text * @param text * the text to tokenize and index. * @param analyzer * the analyzer to use for tokenization */ public void addField(String fieldName, String text, Analyzer analyzer) { if (fieldName == null) throw new IllegalArgumentException("fieldName must not be null"); if (text == null) throw new IllegalArgumentException("text must not be null"); if (analyzer == null) throw new IllegalArgumentException("analyzer must not be null"); TokenStream stream = analyzer.tokenStream(fieldName, text); storeTerms(getInfo(fieldName, defaultFieldType), stream, analyzer.getPositionIncrementGap(fieldName), analyzer.getOffsetGap(fieldName)); }
Info info = getInfo(field.name(), field.fieldType());