当前位置: 首页>>代码示例>>Java>>正文


Java SpellChecker.close方法代码示例

本文整理汇总了Java中org.apache.lucene.search.spell.SpellChecker.close方法的典型用法代码示例。如果您正苦于以下问题:Java SpellChecker.close方法的具体用法?Java SpellChecker.close怎么用?Java SpellChecker.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.search.spell.SpellChecker的用法示例。


在下文中一共展示了SpellChecker.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSpellCheckerIndex

import org.apache.lucene.search.spell.SpellChecker; //导入方法依赖的package包/类
protected void buildSpellCheckerIndex(SearchFactory searchFactory) {
	IndexReader reader = null;
	Directory dir = null;
	long _entr = System.currentTimeMillis();
	File spellCheckIndexDir = new File("lucene_index/spellcheck");
	log.info("Building SpellChecker index in {0}", spellCheckIndexDir.getAbsolutePath());
	ReaderProvider readerProvider = searchFactory.getReaderProvider();

	try {
		reader = readerProvider.openReader(searchFactory.getDirectoryProviders(NodeDocumentVersion.class)[0]);
		dir = FSDirectory.open(spellCheckIndexDir);
		SpellChecker spell = new SpellChecker(dir);
		spell.clearIndex();
		spell.indexDictionary(new LuceneDictionary(reader, NodeDocument.TEXT_FIELD));
		spell.close();
		dir.close();
		dir = null;
		long _exit = System.currentTimeMillis();
		log.info("Took {1} (ms) to build SpellChecker index in {0}",
				spellCheckIndexDir.getAbsolutePath(), String.valueOf((_exit - _entr)));
	} catch (Exception exc) {
		log.error("Failed to build spell checker index!", exc);
	} finally {
		if (dir != null) {
			try {
				dir.close();
			} catch (Exception zzz) {
			}
		}
		if (reader != null) {
			readerProvider.closeReader(reader);
		}
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:35,代码来源:IndexHelper.java

示例2: forceSpellCheckerRenewal

import org.apache.lucene.search.spell.SpellChecker; //导入方法依赖的package包/类
public static synchronized void forceSpellCheckerRenewal(String indexPath){
    SpellChecker sp = spellCheckMap.get(indexPath);
    if(sp!=null) {
        try {
            sp.close();
        } catch (IOException e) {
            org.webdsl.logging.Logger.error("EXCEPTION",e);
        }
    }
    spellCheckMap.remove(indexPath);
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:12,代码来源:SearchSuggester.java

示例3: updateSpellCheckerIndex

import org.apache.lucene.search.spell.SpellChecker; //导入方法依赖的package包/类
public void updateSpellCheckerIndex(NodeDocumentVersion nDocVer) {
	log.info("Observed Wine added/updated event for {1} from Thread {0}",
			Thread.currentThread().getName(), String.valueOf(nDocVer));
	String text = (nDocVer != null) ? nDocVer.getText() : null;

	if (text != null) {
		Dictionary dictionary = null;

		try {
			FullTextEntityManager ftEm = (FullTextEntityManager) entityManager;
			SearchFactory searchFactory = ftEm.getSearchFactory();
			dictionary = new SetDictionary(text, searchFactory.getAnalyzer("wine_en"));
		} catch (IOException ioExc) {
			log.error("Failed to analyze dictionary text {0} from Wine {1} to update spell checker due to: {2}" +
					text + nDocVer.getUuid() + ioExc.toString());
		}

		if (dictionary != null) {
			Directory dir = null;
			// only allow one thread to update the index at a time ...
			// the Dictionary is pre-computed, so it should happen quickly
			// ...
			// this synchronized approach only works because this component
			// is application-scoped
			synchronized (this) {
				try {
					dir = FSDirectory.open(new File("lucene_index/spellcheck"));
					SpellChecker spell = new SpellChecker(dir);
					spell.indexDictionary(dictionary);
					spell.close();
					log.info("Successfully updated the spell checker index after Document added/updated.");
				} catch (Exception exc) {
					log.error("Failed to update the spell checker index!", exc);
				} finally {
					if (dir != null) {
						try {
							dir.close();
						} catch (Exception zzz) {
						}
					}
				}
			}
		}
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:46,代码来源:IndexHelper.java

示例4: findSpellSuggestionsForField

import org.apache.lucene.search.spell.SpellChecker; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static ArrayList<String> findSpellSuggestionsForField(Class<?> entityClass, String baseDir,
        String suggestedField, int maxSuggestionCount, float accuracy, boolean morePopular,
        Analyzer analyzer, String toSuggestOn) {

    if (toSuggestOn == null || toSuggestOn.isEmpty())
        return new ArrayList<String>();

    SpellChecker spellChecker = null;
    IndexReader fieldIR = null;
    boolean hasSuggestions = false;

    String indexPath = baseDir+suggestedField;
    try {
        spellChecker = getSpellChecker(indexPath);

        spellChecker.setAccuracy(accuracy);

        TokenStream tokenStream = analyzer.tokenStream(suggestedField, new StringReader(
                toSuggestOn));
        CharTermAttributeImpl ta = (CharTermAttributeImpl) tokenStream
                .addAttribute(CharTermAttribute.class);

        ArrayList<String[]> allSuggestions = new ArrayList<String[]>();
        String word;
        String[] suggestions;
        while (tokenStream.incrementToken()) {
            word = ta.term();
            suggestions = null;
            if (!morePopular) {
                suggestions = spellChecker.suggestSimilar(word, maxSuggestionCount);
            } else {
                if (fieldIR == null)
                    fieldIR = getIndexReader(entityClass);
                suggestions = spellChecker.suggestSimilar(word, maxSuggestionCount, fieldIR,
                        suggestedField, true);
            }

            if (suggestions == null || suggestions.length == 0)
                suggestions = new String[] { word };
            else
                hasSuggestions = true;

            allSuggestions.add(suggestions);
        }

        if (!hasSuggestions)
            // if no suggestions were found, return empty list
            return new ArrayList<String>();
        else
            return formSuggestions(maxSuggestionCount, allSuggestions);

    } catch (Exception e) {
        org.webdsl.logging.Logger.error("EXCEPTION",e);
        //if something goes wrong, close and remove current SpellChecker instance, so it gets renewed
        try {
            spellChecker.close();
        } catch (IOException e2) {
            org.webdsl.logging.Logger.error("EXCEPTION",e2);
        }
        spellCheckMap.remove(indexPath);
    }
    finally {
        searchfactory.getReaderProvider().closeReader(fieldIR);
    }
    return new ArrayList<String>();
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:68,代码来源:SearchSuggester.java


注:本文中的org.apache.lucene.search.spell.SpellChecker.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。