@Override public Collection<String> getCoreNames(SolrCore core) { return Arrays.asList(core.getName()); }
@Override public String toString() { return new StringBuilder("Task: building ").append(corpusInfo) .append(" for SolrCore ").append(core.getName()).toString(); }
@Override public String toString() { return new StringBuilder("Task: building ").append(corpusInfo) .append(" for SolrCore ").append(core.getName()).toString(); }
/** * Registers a SolrCore descriptor in the registry using the core's name. * If returnPrev==false, the old core, if different, is closed. * @return a previous core having the same name if it existed and returnPrev==true */ public SolrCore register(SolrCore core, boolean returnPrev) { return register(core.getName(), core, returnPrev); }
@Override public String toString() { return new StringBuilder("Task: building ").append(fstInfo) .append(" for SolrCore ").append(indexConfig.getIndex().getName()).toString(); }
/** * Private constructor due to usage of the Singleton pattern. * * @param container Solr CoreContainer container object. * @param core The Solr Core object. */ private CmsSolrSpellchecker(CoreContainer container, SolrCore core) { if ((null == container) || (null == core)) { throw new IllegalArgumentException(); } m_core = core; m_coreContainer = container; m_solrClient = new EmbeddedSolrServer(m_coreContainer, m_core.getName()); }
protected void finalize() throws Throwable { try { if (getOpenCount() != 0) { log.error("REFCOUNT ERROR: unreferenced " + this + " (" + getName() + ") has a reference count of " + getOpenCount()); } } finally { super.finalize(); } }
@Override public SolrServer addingService(ServiceReference reference) { SolrServer server = super.addingService(reference); if(solrCore != null){ log.info("Multiple SolrCores for name {}! Will update engine " + "with the newly added {}!", new Object[]{solrCore.getName(), indexReference, reference}); } updateEngineRegistration(reference, server); return server; } };
@Override public String lookup(String key) { if("solr-data-dir".equals(key)){ return core.getDataDir(); } else if("solr-index-dir".equals(key)){ return core.getIndexDir(); } else if("solr-server-name".equals(key)){ return indexRef.getServer(); } else if("solr-core-name".equals(key)){ return core.getName(); } else { return bc.getProperty(key); } }
public void run() { try { solrCore.getCoreDescriptor().getCoreContainer().reload(solrCore.getName()); } catch (Exception e) { LOG.error("Could not restart core ", e); } } }.start();
public String getCoreForDirectory(String coreNameOrPath) { if(coreNameOrPath.charAt(coreNameOrPath.length()-1) != File.separatorChar){ coreNameOrPath = coreNameOrPath+File.separatorChar; } for(SolrCore core : server.getCores()){ String instanceDir = core.getCoreDescriptor().getInstanceDir(); if(FilenameUtils.equalsNormalizedOnSystem( coreNameOrPath, instanceDir)){ return core.getName(); } } return null; } public CoreContainer getCoreContainer() {
public String getCoreForDirectory(String coreNameOrPath) { if(coreNameOrPath.charAt(coreNameOrPath.length()-1) != File.separatorChar){ coreNameOrPath = coreNameOrPath+File.separatorChar; } for(SolrCore core : server.getCores()){ String instanceDir = core.getCoreDescriptor().getInstanceDir(); if(FilenameUtils.equalsNormalizedOnSystem( coreNameOrPath, instanceDir)){ return core.getName(); } } return null; } public CoreContainer getCoreContainer() {
/** * Shuts down the Solr core container.<p> */ private void shutDownSolrContainer() { if (m_coreContainer != null) { for (SolrCore core : m_coreContainer.getCores()) { // do not unload spellcheck core because otherwise the core.properties file is removed // even when calling m_coreContainer.unload(core.getName(), false, false, false); if (!core.getName().equals(CmsSolrSpellchecker.SPELLCHECKER_INDEX_CORE)) { m_coreContainer.unload(core.getName(), false, false, true); } } m_coreContainer.shutdown(); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SOLR_SHUTDOWN_SUCCESS_0)); } m_coreContainer = null; } }
@Override public void initialize() throws InitializationException { String solrHome = determineHomeDirectory(); try { // Validate and initialize the home directory if needed. validateAndInitializeHomeDirectory(solrHome); // Start embedded Solr server. this.logger.info("Starting embedded Solr server..."); this.logger.info("Using Solr home directory: [{}]", solrHome); // Initialize the SOLR back-end using an embedded server. this.container = createCoreContainer(solrHome); // If we get here then there is at least one core found. We there are more, we use the first one. String coreName = this.container.getCores().iterator().next().getName(); this.server = new EmbeddedSolrServer(container, coreName); this.logger.info("Started embedded Solr server."); } catch (Exception e) { throw new InitializationException(String.format( "Failed to initialize the Solr embedded server with home directory set to [%s]", solrHome), e); } }
private void informField (FieldDefinition xmlField, SolrCore core) { Map<String,SchemaField> schemaFields = schema.getFields(); Map<String,FieldType> fieldTypes = schema.getFieldTypes(); String fieldName = xmlField.getName(); if (schemaFields.containsKey(fieldName) && xmlField.getType() != Type.TOKENS) { // The Solr schema has a definition for this field, but it's not a TOKENS field: // We're only interested in TOKENS fields here; these need to install their own special field type since they wrap the // analyzer defined by the schema return; } // look up the type of this field using the mapping in this class FieldType fieldType = getFieldType(xmlField); if (! fieldTypes.containsKey(fieldType.getTypeName())) { // The Solr schema does not define this field type, so add it logger.info("{} defining fieldType: {}", core.getName(), fieldType.getTypeName()); fieldTypes.put(fieldType.getTypeName(), fieldType); } else { fieldType = fieldTypes.get(fieldType.getTypeName()); } // Add the field to the schema logger.info(core.getName() + " defining field: {} of type {}", fieldName, fieldType.getTypeName()); schemaFields.put(fieldName, new SchemaField (fieldName, fieldType, xmlField.getSolrFieldProperties(), "")); }
public void inform(SolrCore core) { schema = core.getLatestSchema(); // XML_STORE is not listed explicitly by the indexer informField (indexConfig.getField(FieldRole.XML_STORE), core); // This must be run before informField() registers default analyzers with the Schema registerXmlTextFields(); for (FieldDefinition xmlField : indexConfig.getFields()) { informField (xmlField, core); } if (xpathFieldConfig != null) { addXPathFields(); } SchemaField uniqueKeyField = schema.getUniqueKeyField(); if (uniqueKeyField == null) { logger.error("{} schema does not define any unique field", core.getName()); } else if (! uniqueKeyField.getName().equals(indexConfig.getFieldName(FieldRole.URI))) { logger.error("{} schema defines a different unique field than the uri field declared in lux configuration", core.getName()); } // must call this after making changes to the field map: schema.refreshAnalyzers(); }
/** * Updates the parsed {@link IndexMetadata} instance based on the * properties of the parsed {@link SolrCore}.<p> * This sets the state, index name and the directory. * @param metadata the {@link IndexMetadata} to update * @param core the core */ public static void updateMetadata(IndexMetadata metadata, SolrCore core){ if(metadata == null || core == null){ return; } metadata.setState(ManagedIndexState.ACTIVE); metadata.setIndexName(core.getName()); metadata.setDirectory(core.getCoreDescriptor().getInstanceDir()); } /**
/** * Updates the parsed {@link IndexMetadata} instance based on the * properties of the parsed {@link SolrCore}.<p> * This sets the state, index name and the directory. * @param metadata the {@link IndexMetadata} to update * @param core the core */ public static void updateMetadata(IndexMetadata metadata, SolrCore core){ if(metadata == null || core == null){ return; } metadata.setState(ManagedIndexState.ACTIVE); metadata.setIndexName(core.getName()); metadata.setDirectory(core.getCoreDescriptor().getInstanceDir()); } /**
@Before public void setUp() throws Exception { super.setUp(); solrServer = new EmbeddedSolrServer(h.getCoreContainer(), h.getCore().getName()); }
protected NamedList<Object> getCoreStatus(CoreContainer cores, String cname) throws IOException { NamedList<Object> info = new SimpleOrderedMap<Object>(); SolrCore core = cores.getCore(cname); if (core != null) { try { info.add("name", core.getName()); info.add("instanceDir", normalizePath(core.getResourceLoader().getInstanceDir())); info.add("dataDir", normalizePath(core.getDataDir())); info.add("startTime", new Date(core.getStartTime())); info.add("uptime", System.currentTimeMillis() - core.getStartTime()); RefCounted<SolrIndexSearcher> searcher = core.getSearcher(); try { info.add("index", LukeRequestHandler.getIndexInfo(searcher.get().getReader(), false)); } finally { searcher.decref(); } } finally { core.close(); } } return info; }