/** * Creates a new core based on a CoreDescriptor. * * @param dcore a core descriptor * @param publishState publish core state to the cluster if true * @return the newly created core */ private SolrCore create(CoreDescriptor dcore, boolean publishState) { if (isShutDown) { throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "Solr has been shutdown."); } SolrCore core = null; try { MDCLoggingContext.setCore(core); SolrIdentifierValidator.validateCoreName(dcore.getName()); if (zkSys.getZkController() != null) { zkSys.getZkController().preRegister(dcore); } ConfigSet coreConfig = coreConfigService.getConfig(dcore); log.info( "Creating SolrCore '{}' using configuration from {}", dcore.getName(), coreConfig.getName()); core = new SolrCore(dcore, coreConfig); // always kick off recovery if we are in non-Cloud mode if (!isZooKeeperAware() && core.getUpdateHandler().getUpdateLog() != null) { core.getUpdateHandler().getUpdateLog().recoverFromLog(); } registerCore(dcore.getName(), core, publishState); return core; } catch (Exception e) { coreInitFailures.put(dcore.getName(), new CoreLoadFailure(dcore, e)); log.error("Error creating core [{}]: {}", dcore.getName(), e.getMessage(), e); final SolrException solrException = new SolrException( ErrorCode.SERVER_ERROR, "Unable to create core [" + dcore.getName() + "]", e); if (core != null && !core.isClosed()) IOUtils.closeQuietly(core); throw solrException; } catch (Throwable t) { SolrException e = new SolrException( ErrorCode.SERVER_ERROR, "JVM Error creating core [" + dcore.getName() + "]: " + t.getMessage(), t); log.error("Error creating core [{}]: {}", dcore.getName(), t.getMessage(), t); coreInitFailures.put(dcore.getName(), new CoreLoadFailure(dcore, e)); if (core != null && !core.isClosed()) IOUtils.closeQuietly(core); throw t; } finally { MDCLoggingContext.clear(); } }
private void checkSearch(SolrCore core) throws IOException { addLazy(core, "id", "0"); addLazy(core, "id", "1", "v_t", "Hello Dude"); addLazy(core, "id", "2", "v_t", "Hello Yonik"); addLazy(core, "id", "3", "v_s", "{!literal}"); addLazy(core, "id", "4", "v_s", "other stuff"); addLazy(core, "id", "5", "v_f", "3.14159"); addLazy(core, "id", "6", "v_f", "8983"); SolrQueryRequest req = makeReq(core); CommitUpdateCommand cmtCmd = new CommitUpdateCommand(req, false); core.getUpdateHandler().commit(cmtCmd); // Just get a couple of searches to work! assertQ( "test prefix query", makeReq(core, "q", "{!prefix f=v_t}hel", "wt", "xml"), "//result[@numFound='2']"); assertQ( "test raw query", makeReq(core, "q", "{!raw f=v_t}hello", "wt", "xml"), "//result[@numFound='2']"); // no analysis is done, so these should match nothing assertQ( "test raw query", makeReq(core, "q", "{!raw f=v_t}Hello", "wt", "xml"), "//result[@numFound='0']"); assertQ( "test raw query", makeReq(core, "q", "{!raw f=v_f}1.5", "wt", "xml"), "//result[@numFound='0']"); }
private void addLazy(SolrCore core, String... fieldValues) throws IOException { UpdateHandler updater = core.getUpdateHandler(); AddUpdateCommand cmd = new AddUpdateCommand(makeReq(core)); cmd.solrDoc = sdoc((Object[]) fieldValues); updater.addDoc(cmd); }