本文整理汇总了Java中org.apache.lucene.search.spell.Dictionary类的典型用法代码示例。如果您正苦于以下问题:Java Dictionary类的具体用法?Java Dictionary怎么用?Java Dictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Dictionary类属于org.apache.lucene.search.spell包,在下文中一共展示了Dictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEmptyReader
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Test
public void testEmptyReader() throws IOException {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
iwc.setMergePolicy(newLogMergePolicy());
// Make sure the index is created?
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
writer.commit();
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new DocumentDictionary(ir, FIELD_NAME, WEIGHT_FIELD_NAME, PAYLOAD_FIELD_NAME);
InputIterator inputIterator = dictionary.getEntryIterator();
assertNull(inputIterator.next());
assertEquals(inputIterator.weight(), 0);
assertNull(inputIterator.payload());
ir.close();
dir.close();
}
示例2: testEmptyReader
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Test
public void testEmptyReader() throws IOException {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
iwc.setMergePolicy(newLogMergePolicy());
// Make sure the index is created?
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
writer.commit();
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new DoubleConstValueSource(10), PAYLOAD_FIELD_NAME);
InputIterator inputIterator = dictionary.getEntryIterator();
assertNull(inputIterator.next());
assertEquals(inputIterator.weight(), 0);
assertNull(inputIterator.payload());
ir.close();
dir.close();
}
示例3: create
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if (params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String sourceLocation = (String)params.get(Suggester.LOCATION);
if (sourceLocation == null) {
throw new IllegalArgumentException(Suggester.LOCATION + " parameter is mandatory for using FileDictionary");
}
String fieldDelimiter = (params.get(FIELD_DELIMITER) != null)
? (String) params.get(FIELD_DELIMITER) :
FileDictionary.DEFAULT_FIELD_DELIMITER;
try {
return new FileDictionary(new InputStreamReader(
core.getResourceLoader().openResource(sourceLocation), StandardCharsets.UTF_8), fieldDelimiter);
} catch (IOException e) {
throw new RuntimeException();
}
}
示例4: create
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if(params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String field = (String) params.get(FIELD);
String weightField = (String) params.get(WEIGHT_FIELD);
String payloadField = (String) params.get(PAYLOAD_FIELD);
if (field == null) {
throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
}
if (weightField == null) {
throw new IllegalArgumentException(WEIGHT_FIELD + " is a mandatory parameter");
}
return new DocumentDictionary(searcher.getIndexReader(), field, weightField, payloadField);
}
示例5: create
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if(params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String field = (String)params.get(SolrSpellChecker.FIELD);
if (field == null) {
throw new IllegalArgumentException(SolrSpellChecker.FIELD + " is a mandatory parameter");
}
float threshold = params.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f
: (Float)params.get(THRESHOLD_TOKEN_FREQUENCY);
return new HighFrequencyDictionary(searcher.getIndexReader(), field, threshold);
}
示例6: create
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if (params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String sourceLocation = (String)params.get(Suggester.LOCATION);
if (sourceLocation == null) {
throw new IllegalArgumentException(Suggester.LOCATION + " parameter is mandatory for using FileDictionary");
}
String fieldDelimiter = (params.get(FIELD_DELIMITER) != null)
? (String) params.get(FIELD_DELIMITER) :
FileDictionary.DEFAULT_FIELD_DELIMITER;
try {
return new FileDictionary(new InputStreamReader(
core.getResourceLoader().openResource(sourceLocation), IOUtils.CHARSET_UTF_8), fieldDelimiter);
} catch (IOException e) {
throw new RuntimeException();
}
}
示例7: indexingDone
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Override
public void indexingDone() {
try {
spellChecker = new DirectSpellChecker();
spellChecker.setMaxEdits(2);
spellChecker.setAccuracy(0.1f);
spellChecker.setMinPrefix(0);
reader = DirectoryReader.open(writer);
fuzzySuggester = new FuzzySuggester(directory, "", writer.getAnalyzer());
Dictionary dict = new DocumentValueSourceDictionary(reader, WORD_FIELD, new LongValuesSource() {
@Override
public boolean needsScores() {
return false;
}
@Override
public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
return null;
}
});
fuzzySuggester.build(dict);
writer.close();
searcher = new IndexSearcher(DirectoryReader.open(directory));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例8: createIndexSpellchecker
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@NotNull
private static SpellChecker createIndexSpellchecker(@NotNull final Directory index) throws IOException {
final Directory spellCheckerDirectory = new RAMDirectory();
final IndexReader indexReader = DirectoryReader.open(index);
final Analyzer analyzer = new SimpleAnalyzer();
final IndexWriterConfig config = new IndexWriterConfig(analyzer);
final Dictionary dictionary = new HighFrequencyDictionary(indexReader, DRUG_TERMS_FIELD, 0.0f);
final SpellChecker spellChecker = new SpellChecker(spellCheckerDirectory);
spellChecker.indexDictionary(dictionary, config, false);
spellChecker.setAccuracy(SPELLCHECK_ACCURACY);
return spellChecker;
}
示例9: testEmpty
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
public void testEmpty() throws Exception {
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
writer.commit();
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new HighFrequencyDictionary(ir, "bogus", 0.1f);
BytesRefIterator tf = dictionary.getEntryIterator();
assertNull(tf.getComparator());
assertNull(tf.next());
dir.close();
}
示例10: create
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
@Override
public Dictionary create(SolrCore core, SolrIndexSearcher searcher) {
if(params == null) {
// should not happen; implies setParams was not called
throw new IllegalStateException("Value of params not set");
}
String field = (String) params.get(FIELD);
String payloadField = (String) params.get(PAYLOAD_FIELD);
String weightExpression = (String) params.get(WEIGHT_EXPRESSION);
Set<SortField> sortFields = new HashSet<>();
if (field == null) {
throw new IllegalArgumentException(FIELD + " is a mandatory parameter");
}
if (weightExpression == null) {
throw new IllegalArgumentException(WEIGHT_EXPRESSION + " is a mandatory parameter");
}
for(int i = 0; i < params.size(); i++) {
if (params.getName(i).equals(SORT_FIELD)) {
String sortFieldName = (String) params.getVal(i);
SortField.Type sortFieldType = getSortFieldType(core, sortFieldName);
if (sortFieldType == null) {
throw new IllegalArgumentException(sortFieldName + " could not be mapped to any appropriate type"
+ " [long, int, float, double]");
}
SortField sortField = new SortField(sortFieldName, sortFieldType);
sortFields.add(sortField);
}
}
return new DocumentValueSourceDictionary(searcher.getIndexReader(), field, fromExpression(weightExpression,
sortFields), payloadField);
}
示例11: 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);
}
}
示例12: indexSpellCheck
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
private void indexSpellCheck(String id) throws SearchException {
if(!spellcheck) return;
IndexReader reader=null;
FSDirectory spellDir=null;
Resource dir = _createSpellDirectory(id);
try {
File spellFile = FileWrapper.toFile(dir);
spellDir = FSDirectory.getDirectory(spellFile);
reader = _getReader(id,false);
Dictionary dictionary = new LuceneDictionary(reader,"contents");
SpellChecker spellChecker = new SpellChecker(spellDir);
spellChecker.indexDictionary(dictionary);
}
catch(IOException ioe) {
throw new SearchException(ioe);
}
finally {
flushEL(reader);
closeEL(reader);
}
}
示例13: add
import org.apache.lucene.search.spell.Dictionary; //导入依赖的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());
}
}
示例14: buildSuggesterIndex
import org.apache.lucene.search.spell.Dictionary; //导入依赖的package包/类
private void buildSuggesterIndex() throws IOException {
try (DirectoryReader reader = DirectoryReader.open(indexDir)) {
final Dictionary dictionary = new DocumentDictionary(reader, "content", null, null, "username");
suggester.build(dictionary);
suggester.refresh();
}
}
示例15: 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();
}