Package org.apache.solr.core

Examples of org.apache.solr.core.SolrCore


  }
 

  @Override
  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    SolrCore core = req.getCore();
   
    NamedList cats = new NamedList();
    rsp.add("solr-mbeans", cats);
   
    String[] requestedCats = req.getParams().getParams("cat");
    if (null == requestedCats || 0 == requestedCats.length) {
      for (SolrInfoMBean.Category cat : SolrInfoMBean.Category.values()) {
        cats.add(cat.name(), new SimpleOrderedMap());
      }
    } else {
      for (String catName : requestedCats) {
        cats.add(catName,new SimpleOrderedMap());
      }
    }
        
    Set<String> requestedKeys = arrayToSet(req.getParams().getParams("key"));
   
    Map<String, SolrInfoMBean> reg = core.getInfoRegistry();
    for (Map.Entry<String, SolrInfoMBean> entry : reg.entrySet()) {
      String key = entry.getKey();
      SolrInfoMBean m = entry.getValue();

      if ( ! ( requestedKeys.isEmpty() || requestedKeys.contains(key) ) ) continue;
View Full Code Here


  @Override
  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
  {
    SolrParams params = req.getParams();
    SolrParams required = params.required();
    SolrCore core = req.getCore();
   
    // Check if the service is available
    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);
    }
   
    // Get the RequestHandler
    String qt = required.get( CommonParams.QT );
    SolrRequestHandler handler = core.getRequestHandler( qt );
    if( handler == null ) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
          "Unknown RequestHandler: "+qt );
    }
   
    if( handler instanceof PingRequestHandler ) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
          "Cannot execute the PingRequestHandler recursively" );
    }
   
    // Execute the ping query and catch any possible exception
    Throwable ex = null;
    try {
      SolrQueryResponse pingrsp = new SolrQueryResponse();
      core.execute(handler, req, pingrsp );
      ex = pingrsp.getException();
    }
    catch( Throwable th ) {
      ex = th;
    }
View Full Code Here

   *
   * @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);
View Full Code Here

   *
   * @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 =
View Full Code Here

            CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "",
                    solrConfig.getResourceLoader().getInstanceDir());
            descriptor.setConfigName(solrConfig.getResourceName());
            descriptor.setSchemaName(schema.getResourceName());

            solrCore = new SolrCore(null, solrConfig.getDataDir(),
                    solrConfig, schema, descriptor);
            solrContainer.register("", solrCore, false);
            return new EmbeddedSolrServer(solrContainer, "");
        } catch(Exception ex) {
            log.error("\nFailed to start Solr server\n");
View Full Code Here

    if( path == null || !path.startsWith( "/" ) ) {
      path = "/select";
    }

    // Check for cores action
    SolrCore core =  coreContainer.getCore( coreName );
    if( core == null ) {
      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
                               "No such core: " + coreName );
    }
   
    SolrParams params = request.getParams();
    if( params == null ) {
      params = new ModifiableSolrParams();
    }
   
    // Extract the handler from the path or params
    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);
        }
      }
      // Perhaps the path is to manage the cores
      if( handler == null &&
          coreContainer != null &&
          path.equals( coreContainer.getAdminPath() ) ) {
        handler = coreContainer.getMultiCoreHandler();
      }
    }
    if( handler == null ) {
      core.close();
      throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+path );
    }

    SolrQueryRequest req = null;   
    try {
      req = _parser.buildRequestFrom( core, params, request.getContentStreams() );
      req.getContext().put( "path", path );
      SolrQueryResponse rsp = new SolrQueryResponse();
      core.execute( handler, req, rsp );
      if( rsp.getException() != null ) {
        throw new SolrServerException( rsp.getException() );
      }
     
      // Now write it out
      NamedList<Object> normalized = getParsedResponse(req, rsp);
      return normalized;
    }
    catch( IOException iox ) {
      throw iox;
    }
    catch( Exception ex ) {
      throw new SolrServerException( ex );
    }
    finally {
      try {
        if (req != null) req.close();
      } finally {
        core.close();
      }
    }
  }
View Full Code Here

    try {
      CoreContainer cores = new CoreContainer(new SolrResourceLoader(instanceDir));
      SolrConfig solrConfig = new SolrConfig(instanceDir, SolrConfig.DEFAULT_CONF_FILE, null);
      CoreDescriptor dcore = new CoreDescriptor(cores, "", solrConfig.getResourceLoader().getInstanceDir());
      IndexSchema indexSchema = new IndexSchema(solrConfig, instanceDir+"/conf/schema.xml", null);
      core = new SolrCore( null, dataDir, solrConfig, indexSchema, dcore);
      cores.register("", core, false);
      parser = new SolrRequestParsers( solrConfig );
    }
    catch (Exception ee) {
      throw new RuntimeException(ee);
View Full Code Here

    if( hasMulticore ) {
      response.sendError( 400, "Missing solr core name in path" );
      return;
    }
   
    final SolrCore core = SolrCore.getSolrCore();
    SolrServletRequest solrReq = new SolrServletRequest(core, request);;
    SolrQueryResponse solrRsp = new SolrQueryResponse();
    try {

      SolrRequestHandler handler = core.getRequestHandler(solrReq.getQueryType());
      if (handler==null) {
        log.warn("Unknown Request Handler '" + solrReq.getQueryType() +"' :" + solrReq);
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,"Unknown Request Handler '" + solrReq.getQueryType() + "'", true);
      }
      core.execute(handler, solrReq, solrRsp );
      if (solrRsp.getException() == null) {
        QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
        // Now write it out
        final String ct = responseWriter.getContentType(solrReq, solrRsp);
        // don't call setContentType on null
        if (null != ct) response.setContentType(ct);
        if (responseWriter instanceof BinaryQueryResponseWriter) {
View Full Code Here

    assertU(commit());
  }

  @Test
  public void testProcessorConfiguration() {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain chained = core.getUpdateProcessingChain("uima");
    assertNotNull(chained);
    UIMAUpdateRequestProcessorFactory factory = (UIMAUpdateRequestProcessorFactory) chained
            .getFactories()[0];
    assertNotNull(factory);
    UpdateRequestProcessor processor = factory.getInstance(req(), null, null);
View Full Code Here

    assertTrue(processor instanceof UIMAUpdateRequestProcessor);
  }

  @Test
  public void testMultiMap() {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain chained = core.getUpdateProcessingChain("uima-multi-map");
    assertNotNull(chained);
    UIMAUpdateRequestProcessorFactory factory = (UIMAUpdateRequestProcessorFactory) chained
            .getFactories()[0];
    assertNotNull(factory);
    UpdateRequestProcessor processor = factory.getInstance(req(), null, null);
View Full Code Here

TOP

Related Classes of org.apache.solr.core.SolrCore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.