Java Code Examples for org.apache.solr.core.SolrCore#registerNewSearcherListener()
The following examples show how to use
org.apache.solr.core.SolrCore#registerNewSearcherListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SoftAutoCommitTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Before public void createMonitor() throws Exception { assumeFalse("This test is not working on Windows (or maybe machines with only 2 CPUs)", Constants.WINDOWS); SolrCore core = h.getCore(); updater = (DirectUpdateHandler2) core.getUpdateHandler(); updater.setCommitWithinSoftCommit(true); // foce to default, let tests change as needed monitor = new MockEventListener(); core.registerNewSearcherListener(monitor); updater.registerSoftCommitCallback(monitor); updater.registerCommitCallback(monitor); // isolate searcher getting ready from this test monitor.searcher.poll(5000, MILLISECONDS); }
Example 2
Source File: TestIndexSearcher.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void inform(SolrCore core) { if (registerFirstSearcherListener) { core.registerFirstSearcherListener(new MockSearcherListener()); } if (registerNewSearcherListener) { core.registerNewSearcherListener(new MockSearcherListener()); } if (registerSlowSearcherListener) { core.registerFirstSearcherListener(new SlowSearcherListener()); } }
Example 3
Source File: SpellcheckComponent.java From customized-symspell with MIT License | 4 votes |
private void addSpellChecker(SolrCore core, NamedList spellcheckerNL) { SpellCheckSettings spellCheckSettings = SpellCheckSettings.builder() .deletionWeight(SearchRequestUtil.getFromNamedList(spellcheckerNL, "deleteionWeight", 1.0f)) .insertionWeight( SearchRequestUtil.getFromNamedList(spellcheckerNL, "insertionWeight", 1.0f)) .replaceWeight(SearchRequestUtil.getFromNamedList(spellcheckerNL, "replaceWeight", 1.0f)) .transpositionWeight( SearchRequestUtil.getFromNamedList(spellcheckerNL, "transpositionWeight", 1.0f)) .maxEditDistance( SearchRequestUtil.getFromNamedList(spellcheckerNL, "maxEditDistance", 2.0d)) .prefixLength(SearchRequestUtil.getFromNamedList(spellcheckerNL, "prefixLength", 7)) .verbosity(Verbosity.valueOf( SearchRequestUtil .getFromNamedList(spellcheckerNL, "verbosity", Verbosity.ALL.name()))) .countThreshold(SearchRequestUtil.getFromNamedList(spellcheckerNL, "countThreshold", 10)) .doKeySplit( SearchRequestUtil.getFromNamedList(spellcheckerNL, "createBigram", true)) .keySplitRegex( SearchRequestUtil.getFromNamedList(spellcheckerNL, "bigramSplitRegex", "\\s+")) .build(); StringDistance stringDistance = getStringDistance(spellcheckerNL, spellCheckSettings, core); DataHolder dataHolder = new InMemoryDataHolder(spellCheckSettings, new Murmur3HashFunction()); spellChecker = new SymSpellCheck(dataHolder, stringDistance, spellCheckSettings); String[] fieldList = SearchRequestUtil.getFromNamedList(spellcheckerNL, "field_names", "") .split("\\s+"); // Register event listeners for this SpellChecker customSpellCheckListner = new CustomSpellCheckListner(core, spellChecker, fieldList); core.registerFirstSearcherListener(customSpellCheckListner); String unigramsFile = SearchRequestUtil.getFromNamedList(spellcheckerNL, "unigrams_file", null); String bigramsFile = SearchRequestUtil.getFromNamedList(spellcheckerNL, "bigrams_file", null); String exclusionsFile = SearchRequestUtil .getFromNamedList(spellcheckerNL, "exclusions_file", null); String exclustionnFileSeperator = SearchRequestUtil .getFromNamedList(spellcheckerNL, "exclusions_file_sp", "\\s+"); loadDefault(unigramsFile, bigramsFile, exclusionsFile, spellChecker, core, exclustionnFileSeperator); boolean buildOnCommit = Boolean.parseBoolean((String) spellcheckerNL.get("buildOnCommit")); boolean buildOnOptimize = Boolean.parseBoolean((String) spellcheckerNL.get("buildOnOptimize")); if (buildOnCommit || buildOnOptimize) { log.info("Registering newSearcher listener for spellChecker"); core.registerNewSearcherListener( new CustomSpellCheckListner(core, spellChecker, fieldList)); } }
Example 4
Source File: AsyncBuildSuggestComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void inform(SolrCore core) { if (initParams != null) { LOG.info("Initializing SuggestComponent"); boolean hasDefault = false; for (int i = 0; i < initParams.size(); i++) { if (initParams.getName(i).equals(CONFIG_PARAM_LABEL)) { NamedList suggesterParams = (NamedList) initParams.getVal(i); SolrSuggester suggester = new SolrSuggester(); boolean buildOnStartup; Object buildOnStartupObj = suggesterParams.get(BUILD_ON_STARTUP_LABEL); if (buildOnStartupObj == null) { File storeFile = suggester.getStoreFile(); buildOnStartup = storeFile == null || !storeFile.exists(); } else { buildOnStartup = Boolean.parseBoolean((String) buildOnStartupObj); } boolean buildOnCommit = Boolean.parseBoolean((String) suggesterParams.get(BUILD_ON_COMMIT_LABEL)); boolean buildOnOptimize = Boolean.parseBoolean((String) suggesterParams.get(BUILD_ON_OPTIMIZE_LABEL)); boolean enabled = Boolean.parseBoolean((String) suggesterParams.get(ENABLED_LABEL)); long minSecsBetweenBuilds = Long.parseLong(core.getCoreDescriptor().getCoreProperty(MIN_SECS_BETWEEN_BUILDS, "-1")); SuggesterCache suggesterCache = new SuggesterCache(core, suggesterParams, enabled, buildOnCommit, buildOnOptimize, buildOnStartup); String dictionary = suggester.init(suggesterParams, core); if (dictionary != null) { boolean isDefault = dictionary.equals(DEFAULT_DICT_NAME); if (isDefault && !hasDefault) { hasDefault = true; } else if (isDefault){ throw new RuntimeException("More than one dictionary is missing name."); } suggesterCache.setBeanName(dictionary); suggesters.put(dictionary, suggesterCache); } else { if (!hasDefault){ suggesterCache.setBeanName(DEFAULT_DICT_NAME); suggesters.put(DEFAULT_DICT_NAME, suggesterCache); hasDefault = true; } else { throw new RuntimeException("More than one dictionary is missing name."); } } try { suggesterCache.afterPropertiesSet(); } catch (Exception e) { LOG.error("Unable to initialise SuggesterCache.", e); throw new RuntimeException("Unable to initialise SuggesterCache.", e); } // Register event listeners for this Suggester core.registerFirstSearcherListener(new SuggesterListener(suggesterCache, minSecsBetweenBuilds)); if (buildOnCommit || buildOnOptimize) { LOG.debug("Registering newSearcher listener for suggester: " + suggester.getName()); core.registerNewSearcherListener(new SuggesterListener(suggesterCache, minSecsBetweenBuilds)); } } } } }
Example 5
Source File: SpellCheckComponent.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings({"rawtypes"})private boolean addSpellChecker(SolrCore core, boolean hasDefault, @SuppressWarnings({"rawtypes"})NamedList spellchecker) { String className = (String) spellchecker.get("classname"); if (className == null) className = (String) spellchecker.get("class"); // TODO: this is a little bit sneaky: warn if class isnt supplied // so that it's mandatory in a future release? if (className == null) className = IndexBasedSpellChecker.class.getName(); SolrResourceLoader loader = core.getResourceLoader(); SolrSpellChecker checker = loader.newInstance(className, SolrSpellChecker.class); if (checker != null) { String dictionary = checker.init(spellchecker, core); if (dictionary != null) { boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME); if (isDefault && !hasDefault) { hasDefault = true; } else if (isDefault && hasDefault) { throw new RuntimeException("More than one dictionary is missing name."); } spellCheckers.put(dictionary, checker); } else { if (!hasDefault) { spellCheckers.put(SolrSpellChecker.DEFAULT_DICTIONARY_NAME, checker); hasDefault = true; } else { throw new RuntimeException("More than one dictionary is missing name."); } } // Register event listeners for this SpellChecker core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false)); boolean buildOnCommit = Boolean.parseBoolean((String) spellchecker.get("buildOnCommit")); boolean buildOnOptimize = Boolean.parseBoolean((String) spellchecker.get("buildOnOptimize")); if (buildOnCommit || buildOnOptimize) { if (log.isInfoEnabled()) { log.info("Registering newSearcher listener for spellchecker: {}", checker.getDictionaryName()); } core.registerNewSearcherListener(new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize)); } } else { throw new RuntimeException("Can't load spell checker: " + className); } return hasDefault; }
Example 6
Source File: SuggestComponent.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void inform(SolrCore core) { if (initParams != null) { log.info("Initializing SuggestComponent"); boolean hasDefault = false; for (int i = 0; i < initParams.size(); i++) { if (initParams.getName(i).equals(CONFIG_PARAM_LABEL)) { @SuppressWarnings({"rawtypes"}) NamedList suggesterParams = (NamedList) initParams.getVal(i); SolrSuggester suggester = new SolrSuggester(); String dictionary = suggester.init(suggesterParams, core); if (dictionary != null) { boolean isDefault = dictionary.equals(DEFAULT_DICT_NAME); if (isDefault && !hasDefault) { hasDefault = true; } else if (isDefault){ throw new RuntimeException("More than one dictionary is missing name."); } suggesters.put(dictionary, suggester); } else { if (!hasDefault){ suggesters.put(DEFAULT_DICT_NAME, suggester); hasDefault = true; } else { throw new RuntimeException("More than one dictionary is missing name."); } } boolean buildOnStartup; Object buildOnStartupObj = suggesterParams.get(BUILD_ON_STARTUP_LABEL); if (buildOnStartupObj == null) { File storeFile = suggester.getStoreFile(); buildOnStartup = storeFile == null || !storeFile.exists(); } else { buildOnStartup = Boolean.parseBoolean((String) buildOnStartupObj); } boolean buildOnCommit = Boolean.parseBoolean((String) suggesterParams.get(BUILD_ON_COMMIT_LABEL)); boolean buildOnOptimize = Boolean.parseBoolean((String) suggesterParams.get(BUILD_ON_OPTIMIZE_LABEL)); if (buildOnCommit || buildOnOptimize || buildOnStartup) { SuggesterListener listener = new SuggesterListener(core, suggester, buildOnCommit, buildOnOptimize, buildOnStartup, core.isReloaded()); if (log.isInfoEnabled()) { log.info("Registering searcher listener for suggester: {} = {}", suggester.getName(), listener); } core.registerFirstSearcherListener(listener); core.registerNewSearcherListener(listener); } } } } }
Example 7
Source File: QueryAutoFilteringComponent.java From query-autofiltering-component with Apache License 2.0 | 4 votes |
@Override public void inform( SolrCore core ) { if (initParams != null) { SolrResourceLoader resourceLoader = core.getResourceLoader( ); synonymsFile = (String)initParams.get( "synonyms" ); if (synonymsFile != null) { Analyzer analyzer = new Analyzer() { @Override protected TokenStreamComponents createComponents(String fieldName) { Tokenizer tokenizer = new KeywordTokenizer(); return new TokenStreamComponents(tokenizer, tokenizer ); } }; try { SolrSynonymParser parser = new SolrSynonymParser(true, true, analyzer); CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT) .onUnmappableCharacter(CodingErrorAction.REPORT); parser.parse(new InputStreamReader( resourceLoader.openResource(synonymsFile), decoder)); this.synonyms = parser.build( ); } catch ( Exception e ) { // ??? Log.warn( "Parsing Synonyms Got Exception " + e ); } } String stopwordsFile = (String)initParams.get( "stopwords" ); if (stopwordsFile != null) { this.stopwords = new HashSet<String>( ); try { BufferedReader br = new BufferedReader( new InputStreamReader( resourceLoader.openResource( stopwordsFile ))); String line = null; while ((line = br.readLine( )) != null) { stopwords.add( line.toLowerCase( ) ); } br.close( ); } catch ( IOException ioe ) { Log.warn( "Adding Stopwords Got Exception " + ioe ); } } } core.registerFirstSearcherListener( this ); core.registerNewSearcherListener( this ); }
Example 8
Source File: QueryAutoFilteringComponent.java From query-autofiltering-component with Apache License 2.0 | 4 votes |
@Override public void inform( SolrCore core ) { if (initParams != null) { SolrResourceLoader resourceLoader = core.getResourceLoader( ); synonymsFile = (String)initParams.get( "synonyms" ); if (synonymsFile != null) { Analyzer analyzer = new Analyzer() { @Override protected TokenStreamComponents createComponents(String fieldName, Reader reader) { Tokenizer tokenizer = new KeywordTokenizer( reader ); return new TokenStreamComponents(tokenizer, tokenizer ); } }; try { SolrSynonymParser parser = new SolrSynonymParser(true, true, analyzer); CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT) .onUnmappableCharacter(CodingErrorAction.REPORT); parser.parse(new InputStreamReader( resourceLoader.openResource(synonymsFile), decoder)); this.synonyms = parser.build( ); } catch ( Exception e ) { // ??? Log.warn( "Parsing Synonyms Got Exception " + e ); } } String stopwordsFile = (String)initParams.get( "stopwords" ); if (stopwordsFile != null) { this.stopwords = new HashSet<String>( ); try { BufferedReader br = new BufferedReader( new InputStreamReader( resourceLoader.openResource( stopwordsFile ))); String line = null; while ((line = br.readLine( )) != null) { stopwords.add( line.toLowerCase( ) ); } br.close( ); } catch ( IOException ioe ) { Log.warn( "Adding Stopwords Got Exception " + ioe ); } } } core.registerFirstSearcherListener( this ); core.registerNewSearcherListener( this ); }