本文整理汇总了Java中org.apache.lucene.search.spell.Dictionary.getWordsIterator方法的典型用法代码示例。如果您正苦于以下问题:Java Dictionary.getWordsIterator方法的具体用法?Java Dictionary.getWordsIterator怎么用?Java Dictionary.getWordsIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.spell.Dictionary
的用法示例。
在下文中一共展示了Dictionary.getWordsIterator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: indexDictionary
import org.apache.lucene.search.spell.Dictionary; //导入方法依赖的package包/类
/**
* Indexes the data from the given reader.
* @param reader Source index reader, from which autocomplete words are obtained for the defined field
* @param field the field of the source index reader to index for autocompletion
* @param mergeFactor mergeFactor to use when indexing
* @param ramMB the max amount or memory in MB to use
* @param optimize whether or not the autocomplete index should be optimized
* @throws AlreadyClosedException if the Autocompleter is already closed
* @throws IOException
*/
public final void indexDictionary(IndexReader reader, String field, int mergeFactor, int ramMB, boolean optimize) throws IOException {
synchronized (modifyCurrentIndexLock) {
ensureOpen();
final Directory dir = this.autoCompleteIndex;
final Dictionary dict = new LuceneDictionary(reader, field);
final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT)).setRAMBufferSizeMB(ramMB));
IndexSearcher indexSearcher = obtainSearcher();
final List<IndexReader> readers = new ArrayList<IndexReader>();
if (searcher.maxDoc() > 0) {
ReaderUtil.gatherSubReaders(readers, searcher.getIndexReader());
}
//clear the index
writer.deleteAll();
try {
Iterator<String> iter = dict.getWordsIterator();
while (iter.hasNext()) {
String word = iter.next();
// ok index the word
Document doc = createDocument(word, reader.docFreq(new Term(field, word)));
writer.addDocument(doc);
}
} finally {
releaseSearcher(indexSearcher);
}
// close writer
if (optimize)
writer.optimize();
writer.close();
// also re-open the autocomplete index to see our own changes when the next suggestion
// is fetched:
swapSearcher(dir);
}
}
示例2: testEmpty
import org.apache.lucene.search.spell.Dictionary; //导入方法依赖的package包/类
public void testEmpty() throws Exception {
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
writer.commit();
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new HighFrequencyDictionary(ir, "bogus", 0.1f);
BytesRefIterator tf = dictionary.getWordsIterator();
assertNull(tf.getComparator());
assertNull(tf.next());
dir.close();
}
示例3: build
import org.apache.lucene.search.spell.Dictionary; //导入方法依赖的package包/类
/** Build lookup from a dictionary. Some implementations may require sorted
* or unsorted keys from the dictionary's iterator - use
* {@link SortedInputIterator} or
* {@link UnsortedInputIterator} in such case.
*/
public void build(Dictionary dict) throws IOException {
BytesRefIterator it = dict.getWordsIterator();
InputIterator tfit;
if (it instanceof InputIterator) {
tfit = (InputIterator)it;
} else {
tfit = new InputIterator.InputIteratorWrapper(it);
}
build(tfit);
}