/** 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 { build(dict.getEntryIterator()); }
/** * Look up a key and return possible completion for this key. * @param key lookup key. Depending on the implementation this may be * a prefix, misspelling, or even infix. * @param onlyMorePopular return only more popular results * @param num maximum number of results to return * @return a list of possible completions, with their relative weight (e.g. popularity) */ public List<LookupResult> lookup(CharSequence key, boolean onlyMorePopular, int num) throws IOException { return lookup(key, null, onlyMorePopular, num); }
@Override public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException { LOG.info("reload()"); if (dictionary == null && storeDir != null) { // this may be a firstSearcher event, try loading it FileInputStream is = new FileInputStream(new File(storeDir, factory.storeFileName())); try { if (lookup.load(is)) { return; // loaded ok } } finally { IOUtils.closeWhileHandlingException(is); } LOG.debug("load failed, need to build Lookup again"); } // loading was unsuccessful - build it again build(core, searcher); }
/** * Calls {@link #store(DataOutput)} after converting * {@link OutputStream} to {@link DataOutput} */ public boolean store(OutputStream output) throws IOException { DataOutput dataOut = new OutputStreamDataOutput(output); try { return store(dataOut); } finally { IOUtils.close(output); } }
private List<LookupResult> getLookupResults(SpellingOptions options, Token currentToken) throws IOException { CharsRef scratch = new CharsRef(); scratch.chars = currentToken.buffer(); scratch.offset = 0; scratch.length = currentToken.length(); boolean onlyMorePopular = (options.suggestMode == SuggestMode.SUGGEST_MORE_POPULAR) && !(lookup instanceof WFSTCompletionLookup) && !(lookup instanceof AnalyzingSuggester); List<LookupResult> suggestions = lookup.lookup(scratch, onlyMorePopular, options.count); if (suggestions == null || suggestions.size() == 0) { return null; } return suggestions; }
@Override public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException { LOG.info("reload()"); if (dictionary == null && storeDir != null) { // this may be a firstSearcher event, try loading it FileInputStream is = new FileInputStream(new File(storeDir, factory.storeFileName())); try { if (lookup.load(is)) { return; // loaded ok } } finally { IOUtils.closeWhileHandlingException(is); } LOG.debug("load failed, need to build Lookup again"); } // loading was unsuccessful - build it again build(core, searcher); }
/** Build lookup from a dictionary. Some implementations may require sorted * or unsorted keys from the dictionary's iterator - use * {@link SortedTermFreqIteratorWrapper} or * {@link UnsortedTermFreqIteratorWrapper} in such case. */ public void build(Dictionary dict) throws IOException { BytesRefIterator it = dict.getWordsIterator(); TermFreqIterator tfit; if (it instanceof TermFreqIterator) { tfit = (TermFreqIterator)it; } else { tfit = new TermFreqIterator.TermFreqIteratorWrapper(it); } build(tfit); }
List<LookupResult> suggestions = lookup.lookup(scratch, onlyMorePopular, options.count * 10); if (suggestions == null || suggestions.size() == 0) { continue;
/** * Calls {@link #load(DataInput)} after converting * {@link InputStream} to {@link DataInput} */ public boolean load(InputStream input) throws IOException { DataInput dataIn = new InputStreamDataInput(input); try { return load(dataIn); } finally { IOUtils.close(input); } }
List<Lookup.LookupResult> lookupResults = lookup.lookup(spare.get(), false, suggestionContext.getSize()); for (Lookup.LookupResult res : lookupResults) {
lookup.load(new FileInputStream(new File(storeDir, factory.storeFileName()))); } catch (IOException e) { LOG.warn("Loading stored lookup data failed", e);
List<Lookup.LookupResult> lookupResults = lookup.lookup(spare.get(), false, suggestionContext.getSize()); for (Lookup.LookupResult res : lookupResults) {
lookup.load(new FileInputStream(new File(storeDir, factory.storeFileName()))); } catch (IOException e) { LOG.warn("Loading stored lookup data failed", e);