@Override public void reload() throws IOException { super.reload(); //reload the source initSourceReader(); }
/** * Assumes count = 1, onlyMorePopular = false, extendedResults = false * * @see #getSuggestions(Collection, org.apache.lucene.index.IndexReader, int, boolean, boolean) */ public SpellingResult getSuggestions(Collection<Token> tokens, IndexReader reader) throws IOException { return getSuggestions(tokens, reader, 1, false, false); }
private void buildSpellIndex(SolrIndexSearcher newSearcher) { try { LOG.info("Building spell index for spell checker: " + checker.getDictionaryName()); checker.build(core, newSearcher); } catch (Exception e) { log.error( "Exception in building spell check index for spellchecker: " + checker.getDictionaryName(), e); } }
SpellCheckCollator collator = new SpellCheckCollator() .setMaxCollations(maxCollations) .setMaxCollationTries(maxCollationTries) .setMaxCollationEvaluations(maxCollationEvaluations) .setSuggestionsMayOverlap(suggestionsMayOverlap) .setDocCollectionLimit(maxCollationCollectDocs) List<SpellCheckCollation> collations = collator.collate(spellingResult, q, rb); if (collationExtendedResults) { NamedList extendedResult = new NamedList(); extendedResult.add("collationQuery", collation.getCollationQuery()); extendedResult.add("hits", collation.getHits()); extendedResult.add("misspellingsAndCorrections", collation.getMisspellingsAndCorrections()); if(maxCollationTries>0 && shard) extendedResult.add("collationInternalRank", collation.getInternalRank()); response.add("collation", collation.getCollationQuery()); if(maxCollationTries>0 && shard) response.add("collationInternalRank", collation.getInternalRank());
SpellCheckCollation coll = new SpellCheckCollation(); coll.setCollationQuery((String) o); if(collationRankList!= null && collationRankList.size()>0) coll.setInternalRank((Integer) collationRankList.get(i)); i++; SpellCheckCollation priorColl = collations.get(coll.getCollationQuery()); if(priorColl != null) coll.setInternalRank(Math.max(coll.getInternalRank(),priorColl.getInternalRank())); collations.put(coll.getCollationQuery(), coll); } else SpellCheckCollation coll = new SpellCheckCollation(); coll.setCollationQuery((String) expandedCollation.get("collationQuery")); coll.setHits((Integer) expandedCollation.get("hits")); if(maxCollationTries>0) coll.setInternalRank((Integer) expandedCollation.get("collationInternalRank")); coll.setMisspellingsAndCorrections((NamedList) expandedCollation.get("misspellingsAndCorrections")); SpellCheckCollation priorColl = collations.get(coll.getCollationQuery()); if(priorColl != null) coll.setHits(coll.getHits() + priorColl.getHits()); coll.setInternalRank(Math.max(coll.getInternalRank(),priorColl.getInternalRank()));
SolrSpellChecker checker = (SolrSpellChecker) loader.newInstance(className); if (checker != null) { String dictionary = checker.init(spellchecker, core); if (dictionary != null) { boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME); boolean buildOnOptimize = Boolean.parseBoolean((String) spellchecker.get("buildOnOptimize")); if (buildOnCommit || buildOnOptimize) { LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName()); core.registerNewSearcherListener(new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize)); queryConverters.put("queryConverter", new SpellingQueryConverter()); : fieldType.getQueryAnalyzer(); queryConverter.setAnalyzer(analyzer);
} else { tokens = getTokens(q, spellChecker.getQueryAnalyzer()); SpellingOptions options = new SpellingOptions(tokens, reader, count, alternativeTermCount, suggestMode, extendedResults, accuracy, customParams); spellingResult = spellChecker.getSuggestions(options); } else { spellingResult = new SpellingResult(); addCollationsToResponse(modParams, spellingResult, rb, q, suggestions, spellChecker.isSuggestionsMayOverlap());
@Override @SuppressWarnings("unchecked") public void prepare(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false)) { return; } SolrSpellChecker spellChecker = getSpellChecker(params); if (params.getBool(SPELLCHECK_BUILD, false)) { spellChecker.build(rb.req.getCore(), rb.req.getSearcher()); rb.rsp.add("command", "build"); } else if (params.getBool(SPELLCHECK_RELOAD, false)) { spellChecker.reload(); rb.rsp.add("command", "reload"); } }
public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) { if (currentSearcher == null) { // firstSearcher event try { LOG.info("Loading spell index for spellchecker: " + checker.getDictionaryName()); checker.reload(); } catch (IOException e) { log.error( "Exception in reloading spell check index for spellchecker: " + checker.getDictionaryName(), e); } } else { // newSearcher event if (buildOnCommit) { buildSpellIndex(newSearcher); } else if (buildOnOptimize) { if (newSearcher.getReader().isOptimized()) { buildSpellIndex(newSearcher); } else { LOG.info("Index is not optimized therefore skipping building spell check index for: " + checker.getDictionaryName()); } } } }
boolean extendedResults) throws IOException { SpellingResult result = new SpellingResult(tokens); reader = determineReader(reader); Term term = field != null ? new Term(field, "") : null; for (Token token : tokens) { result.add(token, reader.docFreq(term)); int countLimit = Math.min(count, suggestions.length); for (int i = 0; i < countLimit; i++) { term = term.createTerm(suggestions[i]); result.add(token, suggestions[i], reader.docFreq(term)); suggList = suggList.subList(0, count); result.add(token, suggList);
if (q != null) { tokens = getTokens(q, spellChecker.getQueryAnalyzer()); } else { q = rb.getQueryString(); q = params.get(CommonParams.Q); tokens = queryConverter.convert(q); IndexReader reader = rb.req.getSearcher().getReader(); boolean collate = params.getBool(SPELLCHECK_COLLATE, false); SpellingResult spellingResult = spellChecker.getSuggestions(tokens, reader, count, onlyMorePopular, extendedResults); if (spellingResult != null) {
public String init(NamedList config, SolrCore core) { super.init(config, core); threshold = config.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f : (Float) config.get(THRESHOLD_TOKEN_FREQUENCY); initSourceReader(); return name; }
protected SolrSpellChecker getSpellChecker(SolrParams params) { String[] dictName = getDictionaryNames(params); if (dictName.length == 1) { return spellCheckers.get(dictName[0]); } else { String singleStr = getDictionaryNameAsSingleString(dictName); SolrSpellChecker ssc = spellCheckers.get(singleStr); if (ssc == null) { ConjunctionSolrSpellChecker cssc = new ConjunctionSolrSpellChecker(); for (String dn : dictName) { cssc.addChecker(spellCheckers.get(dn)); } ssc = cssc; } return ssc; } }
public String init(NamedList config, SolrCore core) { super.init(config, core); characterEncoding = (String) config.get(SOURCE_FILE_CHAR_ENCODING); return name; }
public void build(SolrCore core, SolrIndexSearcher searcher) { try { loadExternalFileDictionary(core.getSchema(), core.getResourceLoader()); spellChecker.clearIndex(); spellChecker.indexDictionary(dictionary); } catch (IOException e) { throw new RuntimeException(e); } }
private void buildSpellIndex(SolrIndexSearcher newSearcher) { try { LOG.info("Building spell index for spell checker: " + checker.getDictionaryName()); checker.build(core, newSearcher); } catch (Exception e) { LOG.error( "Exception in building spell check index for spellchecker: " + checker.getDictionaryName(), e); } }
@Override @SuppressWarnings("unchecked") public void prepare(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false)) { return; } SolrSpellChecker spellChecker = getSpellChecker(params); if (params.getBool(SPELLCHECK_BUILD, false)) { spellChecker.build(rb.req.getCore(), rb.req.getSearcher()); rb.rsp.add("command", "build"); } else if (params.getBool(SPELLCHECK_RELOAD, false)) { spellChecker.reload(rb.req.getCore(), rb.req.getSearcher()); rb.rsp.add("command", "reload"); } }
@Override public void newSearcher(SolrIndexSearcher newSearcher, SolrIndexSearcher currentSearcher) { if (currentSearcher == null) { // firstSearcher event try { LOG.info("Loading spell index for spellchecker: " + checker.getDictionaryName()); checker.reload(core, newSearcher); } catch (IOException e) { LOG.error( "Exception in reloading spell check index for spellchecker: " + checker.getDictionaryName(), e); } } else { // newSearcher event if (buildOnCommit) { buildSpellIndex(newSearcher); } else if (buildOnOptimize) { if (newSearcher.getIndexReader().leaves().size() == 1) { buildSpellIndex(newSearcher); } else { LOG.info("Index is not optimized therefore skipping building spell check index for: " + checker.getDictionaryName()); } } } }
/** * Assumes count = 1. * * @see #getSuggestions(Collection, org.apache.lucene.index.IndexReader, int, boolean, boolean) */ public SpellingResult getSuggestions(Collection<Token> tokens, IndexReader reader, boolean onlyMorePopular, boolean extendedResults) throws IOException { return getSuggestions(tokens, reader, 1, onlyMorePopular, extendedResults); }
/** * Assumes onlyMorePopular = false, extendedResults = false * * @see #getSuggestions(Collection, org.apache.lucene.index.IndexReader, int, boolean, boolean) */ public SpellingResult getSuggestions(Collection<Token> tokens, IndexReader reader, int count) throws IOException { return getSuggestions(tokens, reader, count, false, false); }