/** * Initialize using an explicit SolrCore */ public DirectSolrConnection( SolrCore c ) { core = c; parser = new SolrRequestParsers( c.getSolrConfig() ); }
public CommitTracker() { docsSinceCommit = 0; pending = null; docsUpperBound = core.getSolrConfig().getUpdateHandlerInfo().autoCommmitMaxDocs; //getInt("updateHandler/autoCommit/maxDocs", -1); timeUpperBound = core.getSolrConfig().getUpdateHandlerInfo().autoCommmitMaxTime; //getInt("updateHandler/autoCommit/maxTime", -1); SolrCore.log.info("AutoCommit: " + this); }
private void parseEventListeners() { for (PluginInfo pluginInfo : core.getSolrConfig().getPluginInfos(SolrEventListener.class.getName())) { String event = pluginInfo.attributes.get("event"); SolrEventListener listener = core.createEventListener(pluginInfo.className); listener.init(pluginInfo.initArgs); if ("postCommit".equals(event)) { commitCallbacks.add(listener); log.info("added SolrEventListener for postCommit: " + listener); } else if ("postOptimize".equals(event)) { optimizeCallbacks.add(listener); log.info("added SolrEventListener for postOptimize: " + listener); } } }
@Override public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { if (luceneMatchVersion == null) { this.luceneMatchVersion = req.getCore().getSolrConfig().luceneMatchVersion; parseConfig(); } return new SynonymExpandingExtendedDismaxQParser(qstr, localParams, params, req, synonymAnalyzers); }
@Override public Query parse() throws SyntaxError { if (qstr == null || qstr.length()==0) return null; String defaultField = getParam(CommonParams.DF); if (defaultField==null) { defaultField = getReq().getSchema().getDefaultSearchFieldName(); } xmlParser = new XmlQueryParser(defaultField, new StandardAnalyzer(req.getCore().getSolrConfig().luceneMatchVersion)); try { return xmlParser.parse(new ByteArrayInputStream(qstr.getBytes(Charset.forName("utf-8")))); } catch (ParserException e) { throw new SyntaxError (e); } }
public SirenQParser(final String qstr, final SolrParams localParams, final SolrParams params, final SolrQueryRequest req) { super(qstr, localParams, params, req); // change the BooleanQuery maxClauseCount for ALL cores ... // Since QParserPlugin cannot be SolrCoreAware, we cannot do this at plugin init time int maxClauseCount = req.getCore().getSolrConfig().booleanQueryMaxClauseCount; NodeBooleanQuery.setMaxClauseCount(maxClauseCount); TwigQuery.setMaxClauseCount(maxClauseCount); }
/** * Get the user name associated with the request * * @param req the request * @return the user name associated with the request */ public String getUserName(SolrQueryRequest req) throws SolrException { if (binding == null) { throw new SolrException(SolrException.ErrorCode.UNAUTHORIZED, "Solr binding was not created successfully. Defaulting to no access"); } SolrCore solrCore = req.getCore(); HttpServletRequest httpServletRequest = (HttpServletRequest)req.getContext().get("httpRequest"); // LocalSolrQueryRequests won't have the HttpServletRequest because there is no // http request associated with it. if (httpServletRequest == null && !(req instanceof LocalSolrQueryRequest)) { StringBuilder builder = new StringBuilder("Unable to locate HttpServletRequest"); if (solrCore != null && solrCore.getSolrConfig().getBool( "requestDispatcher/requestParsers/@addHttpRequestToContext", true) == false) { builder.append(", ensure requestDispatcher/requestParsers/@addHttpRequestToContext is set to true"); } throw new SolrException(SolrException.ErrorCode.UNAUTHORIZED, builder.toString()); } String superUser = System.getProperty("solr.authorization.superuser", "solr"); // If a local request, treat it like a super user request; i.e. it is equivalent to an // http request from the same process. return req instanceof LocalSolrQueryRequest? superUser:(String)httpServletRequest.getAttribute(USER_NAME); }
public static SolrIndexConfig registerIndexConfiguration (SolrCore core) { // Read the init args from the LuxUpdateProcessorFactory's configuration NamedList<?> initArgs = null; for (PluginInfo info : core.getSolrConfig().getPluginInfos(UpdateRequestProcessorChain.class.getName())) { // FIXME: if there are multiple processors, we prefer the 'default' one, otherwise // just take the last? This is a bit lame, but it provides back-compat. We should at least // raise a warning if this is ambiguous initArgs = info.initArgs; if ("true".equals(info.attributes.get("default"))) { break; } } String configName = SolrIndexConfig.class.getName(); SolrInfoMBean configBean = core.getInfoRegistry().get(configName); SolrIndexConfig indexConfig; if (configBean != null) { indexConfig = (SolrIndexConfig) configBean; } else { int options = (INDEX_PATHS | INDEX_FULLTEXT | STORE_DOCUMENT | SOLR); indexConfig = SolrIndexConfig.makeIndexConfiguration(options, initArgs, configName); indexConfig.inform(core); core.getInfoRegistry().put(configName, indexConfig); } return indexConfig; }
/** 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; } }
protected SolrIndexWriter createMainIndexWriter(String name, boolean removeAllExisting) throws IOException { return new SolrIndexWriter(name,core.getNewIndexDir(), core.getDirectoryFactory(), removeAllExisting, schema, core.getSolrConfig().mainIndexConfig, core.getDeletionPolicy()); }
engine.setProperty("params.resource.loader.instance", new SolrParamResourceLoader(request)); SolrVelocityResourceLoader resourceLoader = new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader()); engine.setProperty("solr.resource.loader.instance", resourceLoader); engine.setProperty(VelocityEngine.RESOURCE_LOADER, "params,file,solr");
setSimilarity(schema.getSimilarity()); SolrConfig solrConfig = core.getSolrConfig(); queryResultWindowSize = solrConfig.queryResultWindowSize; queryResultMaxDocsCached = solrConfig.queryResultMaxDocsCached;
/** * Calculates a tag for the ETag header. * * @param solrReq * @return a tag */ public static String calcEtag(final SolrQueryRequest solrReq) { final SolrCore core = solrReq.getCore(); final long currentIndexVersion = solrReq.getSearcher().getReader().getVersion(); EtagCacheVal etagCache = etagCoreCache.get(core); if (null == etagCache) { final String etagSeed = core.getSolrConfig().getHttpCachingConfig().getEtagSeed(); etagCache = new EtagCacheVal(etagSeed); etagCoreCache.put(core, etagCache); } return etagCache.calcEtag(currentIndexVersion); }
engine.setProperty("solr.resource.loader.instance", new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader()));
final SolrConfig config = core.getSolrConfig();
context.put("display", displayTool); ResourceTool resourceTool = new SolrVelocityResourceTool(request.getCore().getSolrConfig().getResourceLoader().getClassLoader()); resourceTool.configure(toolConfig); context.put("resource", resourceTool);
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);
if (c.getSolrConfig().getBool("abortOnConfigurationError", false)) { abortOnConfigurationError = true; break;
/** * Calculate the appropriate last-modified time for Solr relative the current request. * * @param solrReq * @return the timestamp to use as a last modified time. */ public static long calcLastModified(final SolrQueryRequest solrReq) { final SolrCore core = solrReq.getCore(); final SolrIndexSearcher searcher = solrReq.getSearcher(); final LastModFrom lastModFrom = core.getSolrConfig().getHttpCachingConfig().getLastModFrom(); long lastMod; try { // assume default, change if needed (getOpenTime() should be fast) lastMod = LastModFrom.DIRLASTMOD == lastModFrom ? IndexReader.lastModified(searcher.getReader().directory()) : searcher.getOpenTime(); } catch (IOException e) { // we're pretty freaking screwed if this happens throw new SolrException(ErrorCode.SERVER_ERROR, e); } // Get the time where the searcher has been opened // We get rid of the milliseconds because the HTTP header has only // second granularity return lastMod - (lastMod % 1000L); }
/** * 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); }