Java Code Examples for org.apache.solr.core.SolrCore#getRegisteredSearcher()

The following examples show how to use org.apache.solr.core.SolrCore#getRegisteredSearcher() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScoreJoinQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode, float boost) throws IOException {
  SolrRequestInfo info = SolrRequestInfo.getRequestInfo();

  CoreContainer container = info.getReq().getCore().getCoreContainer();

  final SolrCore fromCore = container.getCore(fromIndex);

  if (fromCore == null) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core join: no such core " + fromIndex);
  }
  RefCounted<SolrIndexSearcher> fromHolder = null;
  fromHolder = fromCore.getRegisteredSearcher();
  final Query joinQuery;
  try {
    joinQuery = JoinUtil.createJoinQuery(fromField, true,
        toField, fromQuery, fromHolder.get(), this.scoreMode);
  } finally {
    fromCore.close();
    fromHolder.decref();
  }
  return joinQuery.rewrite(searcher.getIndexReader()).createWeight(searcher, scoreMode, boost);
}
 
Example 2
Source File: SolrTestCaseJ4.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected static void waitForWarming(SolrCore core) throws InterruptedException {
  RefCounted<SolrIndexSearcher> registeredSearcher = core.getRegisteredSearcher();
  RefCounted<SolrIndexSearcher> newestSearcher = core.getNewestSearcher(false);
  while (registeredSearcher == null || registeredSearcher.get() != newestSearcher.get()) {
    if (registeredSearcher != null) {
      registeredSearcher.decref();
    }
    newestSearcher.decref();
    Thread.sleep(50);
    registeredSearcher = core.getRegisteredSearcher();
    newestSearcher = core.getNewestSearcher(false);
  }
  registeredSearcher.decref();
  newestSearcher.decref();
}
 
Example 3
Source File: JoinQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
JoinParams parseJoin(QParser qparser) throws SyntaxError {
  final String fromField = qparser.getParam("from");
  final String fromIndex = qparser.getParam("fromIndex");
  final String toField = qparser.getParam("to");
  final String v = qparser.localParams.get(QueryParsing.V);
  final String coreName;

  Query fromQuery;
  long fromCoreOpenTime = 0;

  if (fromIndex != null && !fromIndex.equals(qparser.req.getCore().getCoreDescriptor().getName()) ) {
    CoreContainer container = qparser.req.getCore().getCoreContainer();

    // if in SolrCloud mode, fromIndex should be the name of a single-sharded collection
    coreName = ScoreJoinQParserPlugin.getCoreName(fromIndex, container);

    final SolrCore fromCore = container.getCore(coreName);
    if (fromCore == null) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
          "Cross-core join: no such core " + coreName);
    }

    RefCounted<SolrIndexSearcher> fromHolder = null;
    LocalSolrQueryRequest otherReq = new LocalSolrQueryRequest(fromCore, qparser.params);
    try {
      QParser parser = QParser.getParser(v, otherReq);
      fromQuery = parser.getQuery();
      fromHolder = fromCore.getRegisteredSearcher();
      if (fromHolder != null) fromCoreOpenTime = fromHolder.get().getOpenNanoTime();
    } finally {
      otherReq.close();
      fromCore.close();
      if (fromHolder != null) fromHolder.decref();
    }
  } else {
    coreName = null;
    QParser fromQueryParser = qparser.subQuery(v, null);
    fromQueryParser.setIsFilter(true);
    fromQuery = fromQueryParser.getQuery();
  }

  final String indexToUse = coreName == null ? fromIndex : coreName;
  return new JoinParams(fromField, indexToUse, fromQuery, fromCoreOpenTime, toField);
}
 
Example 4
Source File: ZkController.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * Ensures that a searcher is registered for the given core and if not, waits until one is registered
 */
private static void ensureRegisteredSearcher(SolrCore core) throws InterruptedException {
  if (!core.getSolrConfig().useColdSearcher) {
    RefCounted<SolrIndexSearcher> registeredSearcher = core.getRegisteredSearcher();
    if (registeredSearcher != null) {
      if (log.isDebugEnabled()) {
        log.debug("Found a registered searcher: {} for core: {}", registeredSearcher.get(), core);
      }
      registeredSearcher.decref();
    } else  {
      @SuppressWarnings({"rawtypes"})
      Future[] waitSearcher = new Future[1];
      if (log.isInfoEnabled()) {
        log.info("No registered searcher found for core: {}, waiting until a searcher is registered before publishing as active", core.getName());
      }
      final RTimer timer = new RTimer();
      RefCounted<SolrIndexSearcher> searcher = null;
      try {
        searcher = core.getSearcher(false, true, waitSearcher, true);
        boolean success = true;
        if (waitSearcher[0] != null)  {
          if (log.isDebugEnabled()) {
            log.debug("Waiting for first searcher of core {}, id: {} to be registered", core.getName(), core);
          }
          try {
            waitSearcher[0].get();
          } catch (ExecutionException e) {
            log.warn("Wait for a searcher to be registered for core {}, id: {} failed due to: {}", core.getName(), core, e, e);
            success = false;
          }
        }
        if (success)  {
          if (searcher == null) {
            // should never happen
            if (log.isDebugEnabled()) {
              log.debug("Did not find a searcher even after the future callback for core: {}, id: {}!!!", core.getName(), core);
            }
          } else  {
            if (log.isInfoEnabled()) {
              log.info("Found a registered searcher: {}, took: {} ms for core: {}, id: {}", searcher.get(), timer.getTime(), core.getName(), core);
            }
          }
        }
      } finally {
        if (searcher != null) {
          searcher.decref();
        }
      }
    }
    RefCounted<SolrIndexSearcher> newestSearcher = core.getNewestSearcher(false);
    if (newestSearcher != null) {
      if (log.isDebugEnabled()) {
        log.debug("Found newest searcher: {} for core: {}, id: {}", newestSearcher.get(), core.getName(), core);
      }
      newestSearcher.decref();
    }
  }
}