List of usage examples for org.apache.solr.core SolrCore getCoreDescriptor
public CoreDescriptor getCoreDescriptor()
From source file:com.adr.bigdata.search.product.fe.BaseSuggestionHandler.java
@Override public void inform(SolrCore core) { super.inform(core); try {//from w w w. ja v a2 s . c o m suggestionLogic = new SuggestionLogic(modelFactory); rdModel = RedisAppContextAdapter.getInstance(readRdProperties(core.getCoreDescriptor())) .getSuggestModel(); rdModel.setTimeToLive( Integer.valueOf(core.getCoreDescriptor().getCoreProperty("redis.suggest.ttl", "3600"))); } catch (Exception e) { getLogger().error("", e); } }
From source file:com.billiger.solr.handler.component.QLTBComponent.java
License:Apache License
/** * Inform component of core reload./*from w ww .j a v a 2 s . co m*/ * * This will both set the analyzer according to the configured * queryFieldType, and load the QLTB data. Data source can be (in this * order) ZooKeeper, the conf/ directory or the data/ directory. */ @Override public final void inform(final SolrCore core) { // load analyzer String queryFieldType = initArgs.get(FIELD_TYPE); if (queryFieldType != null) { FieldType ft = core.getLatestSchema().getFieldTypes().get(queryFieldType); if (ft == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "unknown FieldType \"" + queryFieldType + "\" used in QLTBComponent"); } analyzer = ft.getQueryAnalyzer(); } else { analyzer = null; } synchronized (qltbCache) { qltbCache.clear(); try { // retrieve QLTB data filename String qltbFile = initArgs.get(QLTB_FILE); if (qltbFile == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QLTBComponent must specify argument: \"" + QLTB_FILE + "\" - path to QLTB data"); } boolean exists = false; // check ZooKeeper ZkController zkController = core.getCoreDescriptor().getCoreContainer().getZkController(); if (zkController != null) { exists = zkController.configFileExists(zkController.readConfigName( core.getCoreDescriptor().getCloudDescriptor().getCollectionName()), qltbFile); } else { // no ZooKeeper, check conf/ and data/ directories File fConf = new File(core.getResourceLoader().getConfigDir(), qltbFile); File fData = new File(core.getDataDir(), qltbFile); if (fConf.exists() == fData.exists()) { // both or neither exist throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QLTBComponent missing config file: \"" + qltbFile + "\": either " + fConf.getAbsolutePath() + " or " + fData.getAbsolutePath() + " must exist, but not both"); } if (fConf.exists()) { // conf/ found, load it exists = true; log.info("QLTB source conf/: " + fConf.getAbsolutePath()); Config cfg = new Config(core.getResourceLoader(), qltbFile); qltbCache.put(null, loadQLTBMap(cfg, core)); } } if (!exists) { // Neither ZooKeeper nor conf/, so must be in data/ // We need an IndexReader and the normal RefCounted<SolrIndexSearcher> searcher = null; try { searcher = core.getNewestSearcher(false); IndexReader reader = searcher.get().getIndexReader(); getQLTBMap(reader, core); } finally { if (searcher != null) { searcher.decref(); } } } } catch (Exception ex) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error initializing QltbComponent.", ex); } } }
From source file:com.billiger.solr.handler.component.QLTBComponent.java
License:Apache License
/** * Get QLTB map for the given IndexReader. * * If the QLTB map is located in the conf/ directory, it is independent * of the IndexReader and reloaded only during a core reload. * If, however, QLTB data is read from ZooKeeper or the data/ directory, * it is reloaded for each new IndexReader via the core's resource loader. * * @return QLTB map for the given IndexReader. *///from w ww .jav a 2s . co m private Map<String, List<Query>> getQLTBMap(final IndexReader reader, final SolrCore core) throws Exception { Map<String, List<Query>> map = null; synchronized (qltbCache) { map = qltbCache.get(null); // Magic "null" key for data from conf/ if (map != null) { // QLTB data from the conf/ directory, reader-independent. return map; } map = qltbCache.get(reader); if (map == null) { // No QLTB map for this reader yet, load it from ZooKeeper or // the data/ directory. log.info("load QLTB map for new IndexReader"); String qltbFile = initArgs.get(QLTB_FILE); if (qltbFile == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "QLTBComponent must specify argument: " + QLTB_FILE); } Config cfg; ZkController zkController = core.getCoreDescriptor().getCoreContainer().getZkController(); if (zkController != null) { // We're running under ZooKeeper control... cfg = new Config(core.getResourceLoader(), qltbFile, null, null); } else { // No ZooKeeper, use data/ directory InputStream is = VersionedFile.getLatestFile(core.getDataDir(), qltbFile); cfg = new Config(core.getResourceLoader(), qltbFile, new InputSource(is), null); } map = loadQLTBMap(cfg, core); qltbCache.put(reader, map); } return map; } }
From source file:com.lucid.solr.sidecar.SidecarIndexReaderFactory.java
License:Apache License
DirectoryReader newReaderInternal(Directory indexDir, IndexWriter writer, SolrCore core) throws IOException { DirectoryReader main = null;/*from w ww .j ava 2s. c o m*/ if (writer != null) { main = standardFactory.newReader(writer, core); } else { main = standardFactory.newReader(indexDir, core); } if (!enabled) { LOG.info("Sidecar index not enabled"); return main; } currentCore = core; CoreContainer container = core.getCoreDescriptor().getCoreContainer(); SolrCore source = container.getCore(sourceCollection); if (source == null) { LOG.info("Source collection '" + sourceCollection + "' not present, sidecar index is disabled."); try { return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main), sourceCollection, null); } catch (Exception e1) { LOG.warn("Unexpected exception, returning single main index", e1); return main; } } if (source.isClosed()) { LOG.info("Source collection '" + sourceCollection + "' is closed, sidecar index is disabled."); try { return new SidecarIndexReader(this, main, null, SidecarIndexReader.getSequentialSubReaders(main), sourceCollection, null); } catch (Exception e1) { LOG.warn("Unexpected exception, returning single main index", e1); return main; } } DirectoryReader parallel = null; SolrIndexSearcher searcher = null; try { searcher = source.getNewestSearcher(true).get(); parallel = buildParallelReader(main, searcher, true); } finally { if (searcher != null) { LOG.info("-- closing " + searcher); searcher.close(); } source.close(); } return parallel; }
From source file:com.nominanuda.solr.SingletonSolrAware.java
License:Apache License
public void inform(SolrCore core) { if (coreContainer == null) { coreContainer = core.getCoreDescriptor().getCoreContainer(); }/*w w w. java 2 s . c o m*/ core.addCloseHook(closeHook); }
From source file:com.search.MySearchHandler.java
License:Apache License
/** * Initialize the components based on name. Note, if using * <code>INIT_FIRST_COMPONENTS</code> or <code>INIT_LAST_COMPONENTS</code>, * then the {@link DebugComponent} will always occur last. If this is not * desired, then one must explicitly declare all components using the * <code>INIT_COMPONENTS</code> syntax. */// w w w . j a v a2 s.c o m @Override @SuppressWarnings("unchecked") public void inform(SolrCore core) { Object declaredComponents = initArgs.get(INIT_COMPONENTS); List<String> first = (List<String>) initArgs.get(INIT_FIRST_COMPONENTS); List<String> last = (List<String>) initArgs.get(INIT_LAST_COMPONENTS); List<String> list = null; boolean makeDebugLast = true; if (declaredComponents == null) { // Use the default component list list = getDefaultComponents(); if (first != null) { List<String> clist = first; clist.addAll(list); list = clist; } if (last != null) { list.addAll(last); } } else { list = (List<String>) declaredComponents; if (first != null || last != null) { System.out.println("First/Last components only valid if you do not declare 'components'"); } makeDebugLast = false; } // Build the component list components = new ArrayList<SearchComponent>(list.size()); DebugComponent dbgCmp = null; for (String c : list) { SearchComponent comp = core.getSearchComponent(c); if (comp instanceof DebugComponent && makeDebugLast == true) { dbgCmp = (DebugComponent) comp; } else { components.add(comp); log.debug("Adding component:" + comp); } } if (makeDebugLast == true && dbgCmp != null) { components.add(dbgCmp); log.debug("Adding debug component:" + dbgCmp); } if (shfInfo == null) { shardHandlerFactory = core.getCoreDescriptor().getCoreContainer().getShardHandlerFactory(); } else { shardHandlerFactory = core.createInitInstance(shfInfo, ShardHandlerFactory.class, null, null); core.addCloseHook(new CloseHook() { @Override public void preClose(SolrCore core) { shardHandlerFactory.close(); } @Override public void postClose(SolrCore core) { } }); } }
From source file:com.search.MySearchHandlerTest.java
License:Apache License
/** * Initialize the components based on name. Note, if using <code>INIT_FIRST_COMPONENTS</code> or <code>INIT_LAST_COMPONENTS</code>, * then the {@link DebugComponent} will always occur last. If this is not desired, then one must explicitly declare all components using * the <code>INIT_COMPONENTS</code> syntax. *//*w ww.j a v a2s . co m*/ @Override @SuppressWarnings("unchecked") public void inform(SolrCore core) { Object declaredComponents = initArgs.get(INIT_COMPONENTS); List<String> first = (List<String>) initArgs.get(INIT_FIRST_COMPONENTS); List<String> last = (List<String>) initArgs.get(INIT_LAST_COMPONENTS); List<String> list = null; boolean makeDebugLast = true; if (declaredComponents == null) { // Use the default component list list = getDefaultComponents(); if (first != null) { List<String> clist = first; clist.addAll(list); list = clist; } if (last != null) { list.addAll(last); } } else { list = (List<String>) declaredComponents; if (first != null || last != null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "First/Last components only valid if you do not declare 'components'"); } makeDebugLast = false; } // Build the component list components = new ArrayList<SearchComponent>(list.size()); DebugComponent dbgCmp = null; for (String c : list) { SearchComponent comp = core.getSearchComponent(c); if (comp instanceof DebugComponent && makeDebugLast == true) { dbgCmp = (DebugComponent) comp; } else { components.add(comp); log.debug("Adding component:" + comp); } } if (makeDebugLast == true && dbgCmp != null) { components.add(dbgCmp); log.debug("Adding debug component:" + dbgCmp); } if (shfInfo == null) { shardHandlerFactory = core.getCoreDescriptor().getCoreContainer().getShardHandlerFactory(); } else { shardHandlerFactory = core.createInitInstance(shfInfo, ShardHandlerFactory.class, null, null); core.addCloseHook(new CloseHook() { @Override public void preClose(SolrCore core) { shardHandlerFactory.close(); } @Override public void postClose(SolrCore core) { } }); } }
From source file:org.alfresco.solr.AdminHandlerDistributedTest.java
License:Open Source License
@Test public void newCoreUsingAdminHandler() throws Exception { CoreContainer coreContainer = jettyContainers.get(JETTY_SERVER_ID).getCoreContainer(); //Create the new core AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler(); assertNotNull(coreAdminHandler);//from w w w . ja v a2 s . c o m SolrCore testingCore = createCoreUsingTemplate(coreContainer, coreAdminHandler, CORE_NAME, "rerank", 1, 1); Properties props = testingCore.getCoreDescriptor().getSubstitutableProperties(); //The default sharding method is DB_ID assertEquals(DB_ID.toString(), props.get("shard.method")); //Call custom actions SolrQueryResponse response = callHandler(coreAdminHandler, testingCore, "check"); assertNotNull(response); response = callHandler(coreAdminHandler, testingCore, "summary"); assertSummaryCorrect(response, testingCore.getName()); response = callHandler(coreAdminHandler, testingCore, "Report"); assertNotNull(response); NamedList<Object> report = (NamedList<Object>) response.getValues().get("report"); assertNotNull(report.get(CORE_NAME)); //Create a core using ACL_ID sharding testingCore = createCoreUsingTemplate(coreContainer, coreAdminHandler, CORE_NAME + "aclId", "rerank", 1, 1, "property.shard.method", ACL_ID.toString()); props = testingCore.getCoreDescriptor().getSubstitutableProperties(); assertEquals(ACL_ID.toString(), props.get("shard.method")); }
From source file:org.alfresco.solr.component.AsyncBuildSuggestComponent.java
License:Open Source License
@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); }//from w ww . java2 s. c om 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)); } } } } }
From source file:org.alfresco.solr.component.EnsureModelsComponent.java
License:Open Source License
private ModelTracker registerModelTracker(SolrCore core, AlfrescoCoreAdminHandler adminHandler) { SolrResourceLoader loader = core.getLatestSchema().getResourceLoader(); SolrKeyResourceLoader keyResourceLoader = new SolrKeyResourceLoader(loader); SOLRAPIClientFactory clientFactory = new SOLRAPIClientFactory(); Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getCoreProperties(); SOLRAPIClient repositoryClient = clientFactory.getSOLRAPIClient(props, keyResourceLoader, AlfrescoSolrDataModel.getInstance().getDictionaryService(CMISStrictDictionaryService.DEFAULT), AlfrescoSolrDataModel.getInstance().getNamespaceDAO()); String solrHome = core.getCoreDescriptor().getCoreContainer().getSolrHome(); SolrContentStore solrContentStore = new SolrContentStore(CoreWatcherJob.locateContentHome(solrHome)); SolrInformationServer srv = new SolrInformationServer(adminHandler, core, repositoryClient, solrContentStore);//from w w w . j a v a 2 s .com ModelTracker mTracker = new ModelTracker(solrHome, props, repositoryClient, core.getName(), srv); TrackerRegistry trackerRegistry = adminHandler.getTrackerRegistry(); trackerRegistry.setModelTracker(mTracker); SolrTrackerScheduler scheduler = adminHandler.getScheduler(); scheduler.schedule(mTracker, core.getName(), props); return mTracker; }