@Override public Collection<String> getCoreNames(SolrCore core) { return Arrays.asList(core.getName()); }
public SolandraCoreContainer(String solrConfigFile) throws ParserConfigurationException, IOException, SAXException { this.solrConfigFile = solrConfigFile; SolrConfig solrConfig = new SolrConfig(solrConfigFile); CoreDescriptor dcore = new CoreDescriptor(null, "", "."); singleCore = new SolrCore("", "/tmp", solrConfig, null, dcore); }
SchemaField uniqueField = core.getSchema().getUniqueKeyField();
ContentStream stream, UpdateRequestProcessor processor) throws Exception { Parser parser = null; String streamType = req.getParams().get(ExtractingParams.STREAM_TYPE, null); if (streamType != null) { String resourceName = req.getParams().get(ExtractingParams.RESOURCE_NAME, null); if (resourceName != null) { metadata.add(TikaMetadataKeys.RESOURCE_NAME_KEY, resourceName); InputStream is = req.getCore().getResourceLoader().openResource(pwMapFile); if(is != null) { log.debug("Password file supplied: "+pwMapFile); .append(". metadata=").append(metadata.toString()).toString()); else throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); serializer.endDocument(); rsp.add(stream.getName() + "_metadata", metadataNL); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); } finally { IOUtils.closeQuietly(inputStream); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Stream type of " + streamType + " didn't match any known parsers. Please supply the " + ExtractingParams.STREAM_TYPE + " parameter.");
long timeAllowed = rb.req.getParams().getLong(CommonParams.TIME_ALLOWED, -1L); if (timeAllowed > 0L) { SolrQueryTimeoutImpl.set(timeAllowed); if (rb.req.getCore().getSolrConfig().luceneMatchVersion.onOrAfter(Version.LUCENE_6_0_0)) { String reqPath = (String) rb.req.getContext().get(PATH); if (!"/select".equals(reqPath)) { params.set(CommonParams.QT, reqPath); boolean tolerant = rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false); while (rb.outgoing.size() == 0) { ShardResponse srsp = tolerant ? shardHandler1.takeCompletedIncludingErrors() : shardHandler1 throw (SolrException) srsp.getException(); } else { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, srsp.getException()); if(rb.rsp.getResponseHeader().get(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY) == null) { rb.rsp.getResponseHeader().add(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY, Boolean.TRUE); shardInfo.add(shardInfoName, nl); rb.rsp.getValues().add(ShardParams.SHARDS_INFO,shardInfo);
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { rsp.setHttpCaching(false); Iterable<ContentStream> streams = req.getContentStreams(); if(streams != null){ for (ContentStream stream : streams) { String dataConfigFile = params.get("config"); String dataConfig = params.get("dataConfig"); if(dataConfigFile != null) { dataConfig = SolrWriter.getResourceAsString(req.getCore().getResourceLoader().openResource(dataConfigFile)); rsp.add("status", DataImporter.MSG.NO_CONFIG_FOUND); } else { req.setParams(rawParams); ContentStreamBase content = new ContentStreamBase.StringStream(dataConfig); rsp.add(RawResponseWriter.CONTENT, content); importer.maybeReloadConfiguration(requestParams, defaultParams); UpdateRequestProcessorChain processorChain = req.getCore().getUpdateProcessorChain(params); UpdateRequestProcessor processor = processorChain.createProcessor(req, rsp); SolrResourceLoader loader = req.getCore().getResourceLoader(); DIHWriter sw = getSolrWriter(processor, loader, requestParams, req);
String alternate = cores.getManagementPath(); if (alternate != null && path.startsWith(alternate)) { path = path.substring(0, alternate.length()); if( path.equals( cores.getAdminPath() ) ) { handler = cores.getMultiCoreHandler(); solrReq = adminRequestParser.parse(null,path, req); handleAdminRequest(req, response, handler, solrReq); final SolrConfig config = core.getSolrConfig(); handler = core.getRequestHandler( path ); String qt = solrReq.getParams().get( CommonParams.QT ); handler = core.getRequestHandler( qt ); if( handler == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq); writeResponse(solrRsp, response, responseWriter, solrReq, reqMethod); solrReq.close(); core.close();
SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.NAME); CoreDescriptor dcore = new CoreDescriptor(coreContainer, name, params.get(CoreAdminParams.INSTANCE_DIR)); String opts = params.get(CoreAdminParams.CONFIG); if (opts != null) dcore.setConfigName(opts); opts = params.get(CoreAdminParams.SCHEMA); if (opts != null) dcore.setSchemaName(opts); opts = params.get(CoreAdminParams.DATA_DIR); dcore.setCoreProperties(null); SolrCore core = coreContainer.create(dcore); coreContainer.register(name, core, false); rsp.add("core", core.getName()); return coreContainer.isPersistent(); } catch (Exception ex) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error executing default implementation of CREATE", ex);
final SolrIndexSearcher searcher = newSearcher; log.info("QuerySenderListener sending requests to " + newSearcher); for (NamedList nlst : (List<NamedList>)args.get("queries")) { try { core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp); for (int i=0; i<values.size(); i++) { Object o = values.getVal(i); if (o instanceof DocList) { DocList docs = (DocList)o;
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception SolrParams params = req.getParams(); SolrParams required = params.required(); SolrCore core = req.getCore(); String healthcheck = core.getSolrConfig().get("admin/healthcheck/text()", null ); if( healthcheck != null && !new File(healthcheck).exists() ) { throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Service disabled", true); String qt = required.get( CommonParams.QT ); SolrRequestHandler handler = core.getRequestHandler( qt ); if( handler == null ) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown RequestHandler: "+qt ); try { SolrQueryResponse pingrsp = new SolrQueryResponse(); core.execute(handler, req, pingrsp ); ex = pingrsp.getException(); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Ping query caused exception: "+ex.getMessage(), ex );
public void inform(SolrCore core) { if (initArgs != null) { String tikaConfigLoc = (String) initArgs.get(CONFIG_LOCATION); if (tikaConfigLoc != null) { File configFile = new File(tikaConfigLoc); if (configFile.isAbsolute() == false) { configFile = new File(core.getResourceLoader().getConfigDir(), configFile.getPath()); throw new SolrException(ErrorCode.SERVER_ERROR, e); config = TikaConfig.getDefaultConfig(); } catch (TikaException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e); NamedList configDateFormats = (NamedList) initArgs.get(DATE_FORMATS); if (configDateFormats != null && configDateFormats.size() > 0) { dateFormats = new HashSet<String>(); while (configDateFormats.iterator().hasNext()) { config = TikaConfig.getDefaultConfig(); } catch (TikaException e) { throw new SolrException(ErrorCode.SERVER_ERROR, e);
/** * Constructs a base collapser. * * @param rb The response builder * @param collapseCollectorFactories A list of collapse collector factories configured for the document collapser * @throws IOException if index searcher related problems occur */ protected AbstractDocumentCollapser(ResponseBuilder rb, List<CollapseCollectorFactory> collapseCollectorFactories) throws IOException { this.collapseCollectorFactories = collapseCollectorFactories; // Allocate data structures hashMaxSize = rb.req.getCore().getSolrConfig().hashDocSetMaxSize; docbuf = new int[hashMaxSize]; this.searcher = rb.req.getSearcher(); this.flags = rb.getFieldFlags(); // parsing Solr parameters SolrParams params = rb.req.getParams(); collapseField = params.required().get(CollapseParams.COLLAPSE_FIELD); Integer ct = params.getInt(CollapseParams.COLLAPSE_THRESHOLD); if (ct == null) { ct = params.getInt(CollapseParams.COLLAPSE_MAX); } collapseThreshold = ct != null ? ct : 1; checkCollapseField(rb.req.getSchema()); int collapseMaxDocs = params.getInt(CollapseParams.COLLAPSE_MAXDOCS, 0); this.collapseMaxDocs = collapseMaxDocs <= 0 ? searcher.maxDoc() : collapseMaxDocs; includeDebugInformation = params.getBool(CollapseParams.COLLAPSE_DEBUG ,false); collapseContext = new CollapseContext(); collectors = initializeCollapseCollectors(rb.req); }
SolrRequestHandler handler = core.getRequestHandler( path ); if( handler == null ) { if( "/select".equals( path ) || "/select/".equalsIgnoreCase( path) ) { String qt = params.get( CommonParams.QT ); handler = core.getRequestHandler( qt ); if( handler == null ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt); path.equals( coreContainer.getAdminPath() ) ) { handler = coreContainer.getMultiCoreHandler(); core.close(); throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+path ); req.getContext().put( "path", path ); SolrQueryResponse rsp = new SolrQueryResponse(); core.execute( handler, req, rsp ); if( rsp.getException() != null ) { throw new SolrServerException( rsp.getException() ); req.close(); return normalized; core.close();
protected boolean handleMergeAction(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { boolean doPersist = false; SolrParams params = req.getParams(); SolrParams required = params.required(); String cname = required.get(CoreAdminParams.CORE); SolrCore core = coreContainer.getCore(cname); if (core != null) { try { doPersist = coreContainer.isPersistent(); String[] dirNames = required.getParams(CoreAdminParams.INDEX_DIR); DirectoryFactory dirFactory = core.getDirectoryFactory(); Directory[] dirs = new Directory[dirNames.length]; for (int i = 0; i < dirNames.length; i++) { dirs[i] = dirFactory.open(dirNames[i]); } UpdateRequestProcessorChain processorChain = core.getUpdateProcessingChain(params.get(UpdateParams.UPDATE_PROCESSOR)); SolrQueryRequest wrappedReq = new LocalSolrQueryRequest(core, req.getParams()); UpdateRequestProcessor processor = processorChain.createProcessor(wrappedReq, rsp); processor.processMergeIndexes(new MergeIndexesCommand(dirs)); } finally { core.close(); } } return doPersist; }
/** * Handle "UNLOAD" Action * * @param req * @param rsp * * @return true if a modification has resulted that requires persistance * of the CoreContainer configuration. */ protected boolean handleUnloadAction(SolrQueryRequest req, SolrQueryResponse rsp) throws SolrException { SolrParams params = req.getParams(); String cname = params.get(CoreAdminParams.CORE); SolrCore core = coreContainer.remove(cname); if(core == null){ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No such core exists '"+cname+"'"); } core.close(); return coreContainer.isPersistent(); }
@Override public CoreContainer initialize() { CoreContainer container = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome())); CoreDescriptor dcore = new CoreDescriptor(container, coreName, solrConfig.getResourceLoader().getInstanceDir()); dcore.setConfigName(solrConfig.getResourceName()); dcore.setSchemaName(indexSchema.getResourceName()); SolrCore core = new SolrCore( null, dataDirectory, solrConfig, indexSchema, dcore); container.register(coreName, core, false); return container; } }
/** * Handle "RENAME" Action * * @param req * @param rsp * * @return true if a modification has resulted that requires persistance * of the CoreContainer configuration. * * @throws SolrException */ protected boolean handleRenameAction(SolrQueryRequest req, SolrQueryResponse rsp) throws SolrException { SolrParams params = req.getParams(); String name = params.get(CoreAdminParams.OTHER); String cname = params.get(CoreAdminParams.CORE); boolean doPersist = false; if (cname.equals(name)) return doPersist; SolrCore core = coreContainer.getCore(cname); if (core != null) { doPersist = coreContainer.isPersistent(); coreContainer.register(name, core, false); coreContainer.remove(cname); core.close(); } return doPersist; }
/** Get Transformer from request context, or from TransformerProvider. * This allows either getContentType(...) or write(...) to instantiate the Transformer, * depending on which one is called first, then the other one reuses the same Transformer */ protected Transformer getTransformer(SolrQueryRequest request) throws IOException { final String xslt = request.getParams().get(TRANSFORM_PARAM,null); if(xslt==null) { throw new IOException("'" + TRANSFORM_PARAM + "' request parameter is required to use the XSLTResponseWriter"); } // not the cleanest way to achieve this SolrConfig solrConfig = request.getCore().getSolrConfig(); // no need to synchronize access to context, right? // Nothing else happens with it at the same time final Map<Object,Object> ctx = request.getContext(); Transformer result = (Transformer)ctx.get(CONTEXT_TRANSFORMER_KEY); if(result==null) { result = TransformerProvider.instance.getTransformer(solrConfig, xslt,xsltCacheLifetimeSeconds.intValue()); ctx.put(CONTEXT_TRANSFORMER_KEY,result); } return result; } }
/** * Get a reference to the searcher for the required collection. If the collection is * not the same as the search collection, we assume it is under the same Solr instance. * @param rb the response builder holding the facets. * @return a counted reference to the searcher. * @throws SolrException if the collection cannot be found. */ private RefCounted<SolrIndexSearcher> getSearcherReference(ResponseBuilder rb) throws SolrException { RefCounted<SolrIndexSearcher> searcherRef; SolrCore currentCore = rb.req.getCore(); if (StringUtils.isBlank(collection)) { searcherRef = currentCore.getSearcher(); } else { // Using an alternative core - find it SolrCore reqCore = currentCore.getCoreDescriptor().getCoreContainer().getCore(collection); if (reqCore == null) { throw new SolrException(ErrorCode.BAD_REQUEST, "Collection \"" + collection + "\" cannot be found"); } searcherRef = reqCore.getSearcher(); } return searcherRef; }
/** * Forwards the control to the appropriate {@link RequestHandlerBase}. * * @param request the current Solr query request. * @param response the current Solr query response. * @param requestHandlerName the target requestHandler name. * @param defaultRequestHandlerName the default request handler name (in case of absence of the preceding handler). */ void forward(final SolrQueryRequest request, final SolrQueryResponse response, final String requestHandlerName, final String defaultRequestHandlerName) { request.getCore() .getRequestHandler( request.getParams().get(requestHandlerName, defaultRequestHandlerName)) .handleRequest(request, response); } }