本文整理汇总了Java中org.apache.lucene.search.suggest.InputIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java InputIterator.next方法的具体用法?Java InputIterator.next怎么用?Java InputIterator.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.suggest.InputIterator
的用法示例。
在下文中一共展示了InputIterator.next方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rebuild
import org.apache.lucene.search.suggest.InputIterator; //导入方法依赖的package包/类
/**
* Rebuild a suggestion index from the document index.
*
* This method iterates through the entire document index and makes sure that only unique titles
* are indexed.
*
* @param indexRoot The parent directory inside which both the document index and the suggestion
* index lives.
* @throws IOException
*/
public static void rebuild(String indexRoot) throws IOException {
Path indexRootPath = Paths.get(indexRoot);
Path suggestionPath = getSuggestionIndexPath(indexRootPath);
// Delete the suggestion index if it exists.
if (Files.exists(suggestionPath)) {
Util.deletePath(suggestionPath);
}
// Create the suggestion index.
Analyzer analyzer = Indexer.getAnalyzer();
Directory suggestionDir = FSDirectory.open(getSuggestionIndexPath(indexRootPath));
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(suggestionDir, analyzer);
// Open the document index.
Directory indexDir = FSDirectory.open(Indexer.getMainIndexPath(indexRootPath));
IndexReader reader = DirectoryReader.open(indexDir);
// Get a document iterator.
DocumentDictionary docDict = new DocumentDictionary(reader, Indexer.TITLE_FIELD_NAME, null);
InputIterator iterator = docDict.getEntryIterator();
Set<BytesRef> titleSet = new HashSet<>();
BytesRef next;
while ((next = iterator.next()) != null) {
if (titleSet.contains(next)) {
continue;
}
titleSet.add(next);
suggester.add(next, null, 0, null);
}
reader.close();
suggester.commit();
suggester.close();
}
示例2: build
import org.apache.lucene.search.suggest.InputIterator; //导入方法依赖的package包/类
@Override
public void build(InputIterator iterator) throws IOException {
if (iterator.hasPayloads()) {
throw new IllegalArgumentException("this suggester doesn't support payloads");
}
BytesRef scratch = new BytesRef();
InputIterator iter = new WFSTInputIterator(iterator);
IntsRef scratchInts = new IntsRef();
BytesRef previous = null;
PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, outputs);
while ((scratch = iter.next()) != null) {
long cost = iter.weight();
if (previous == null) {
previous = new BytesRef();
} else if (scratch.equals(previous)) {
continue; // for duplicate suggestions, the best weight is actually
// added
}
Util.toIntsRef(scratch, scratchInts);
builder.add(scratchInts, cost);
previous.copyBytes(scratch);
}
fst = builder.finish();
}
示例3: add
import org.apache.lucene.search.suggest.InputIterator; //导入方法依赖的package包/类
/**
* Like build(), but without flushing the old entries, and *ignores duplicate entries*
*
* @param dict
* @throws IOException
*/
public void add(Dictionary dict) throws IOException {
InputIterator iter = dict.getEntryIterator();
BytesRef text;
while ((text = iter.next()) != null) {
if (lookup(text.utf8ToString(), 1, true, false).size() > 0) {
continue;
}
add(text, iter.contexts(), iter.weight(), iter.payload());
}
}
示例4: build
import org.apache.lucene.search.suggest.InputIterator; //导入方法依赖的package包/类
@Override
public void build(InputIterator iterator) throws IOException {
if (iterator.hasPayloads()) {
throw new IllegalArgumentException("this suggester doesn't support payloads");
}
count = 0;
BytesRef scratch = new BytesRef();
InputIterator iter = new WFSTInputIterator(iterator);
IntsRef scratchInts = new IntsRef();
BytesRef previous = null;
PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
Builder<Long> builder = new Builder<Long>(FST.INPUT_TYPE.BYTE1, outputs);
while ((scratch = iter.next()) != null) {
long cost = iter.weight();
if (previous == null) {
previous = new BytesRef();
} else if (scratch.equals(previous)) {
continue; // for duplicate suggestions, the best weight is actually
// added
}
Util.toIntsRef(scratch, scratchInts);
builder.add(scratchInts, cost);
previous.copyBytes(scratch);
count++;
}
fst = builder.finish();
}