类org.apache.lucene.index.ExitableDirectoryReader源码实例Demo

下面列出了怎么用org.apache.lucene.index.ExitableDirectoryReader的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lucene-solr   文件: Grouping.java
/**
 * Invokes search with the specified filter and collector.  
 * If a time limit has been specified, wrap the collector in a TimeLimitingCollector
 */
private void searchWithTimeLimiter(final Filter luceneFilter, Collector collector) throws IOException {
  if (cmd.getTimeAllowed() > 0) {
    if (timeLimitingCollector == null) {
      timeLimitingCollector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), cmd.getTimeAllowed());
    } else {
      /*
       * This is so the same timer can be used for grouping's multiple phases.   
       * We don't want to create a new TimeLimitingCollector for each phase because that would 
       * reset the timer for each phase.  If time runs out during the first phase, the 
       * second phase should timeout quickly.
       */
      timeLimitingCollector.setCollector(collector);
    }
    collector = timeLimitingCollector;
  }
  try {
    searcher.search(QueryUtils.combineQueryAndFilter(query, luceneFilter), collector);
  } catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) {
    log.warn("Query: {}; {}", query, x.getMessage());
    qr.setPartialResults(true);
  }
}
 
源代码2 项目: mtas   文件: MtasSolrSearchComponent.java
@Override
public void handleResponses(ResponseBuilder rb, ShardRequest sreq) {
	 // System.out
	 // .println(System.nanoTime() + " - " + Thread.currentThread().getId()
	 // + " - " + rb.req.getParams().getBool(ShardParams.IS_SHARD, false)
	 // + " HANDLERESPONSES " + rb.stage + " " + rb.req.getParamString());
	MtasSolrStatus solrStatus = Objects
			.requireNonNull((MtasSolrStatus) rb.req.getContext().get(MtasSolrStatus.class), "couldn't find status");
	solrStatus.setStage(rb.stage);
	try {
		if (rb.req.getParams().getBool(PARAM_MTAS, false)) {

			// do nothing
		}
	} catch (ExitableDirectoryReader.ExitingReaderException e) {
		solrStatus.setError(e.getMessage());
	}
}
 
源代码3 项目: lucene-solr   文件: CommandHandler.java
/**
 * Invokes search with the specified filter and collector.  
 * If a time limit has been specified then wrap the collector in the TimeLimitingCollector
 */
private void searchWithTimeLimiter(Query query, 
                                   ProcessedFilter filter, 
                                   Collector collector) throws IOException {
  if (queryCommand.getTimeAllowed() > 0 ) {
    collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), queryCommand.getTimeAllowed());
  }

  TotalHitCountCollector hitCountCollector = new TotalHitCountCollector();
  if (includeHitCount) {
    collector = MultiCollector.wrap(collector, hitCountCollector);
  }

  query = QueryUtils.combineQueryAndFilter(query, filter.filter);

  if (filter.postFilter != null) {
    filter.postFilter.setLastDelegate(collector);
    collector = filter.postFilter;
  }

  try {
    searcher.search(query, collector);
  } catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) {
    partialResults = true;
    log.warn("Query: {}; {}", query, x.getMessage());
  }

  if (includeHitCount) {
    totalHitCount = hitCountCollector.getTotalHits();
  }
}
 
源代码4 项目: lucene-solr   文件: TrollingIndexReaderFactory.java
private ExitableDirectoryReader wrap(DirectoryReader newReader) throws IOException {
  return new ExitableDirectoryReader(newReader, new QueryTimeout() {
    @Override
    public boolean shouldExit() {
      return trap!=null && trap.shouldExit();
    }
    
    @Override
    public String toString() {
      return ""+trap;
    }
  });
}
 
源代码5 项目: lucene-solr   文件: SolrIndexSearcher.java
/**
 * Builds the necessary collector chain (via delegate wrapping) and executes the query against it. This method takes
 * into consideration both the explicitly provided collector and postFilter as well as any needed collector wrappers
 * for dealing with options specified in the QueryCommand.
 * @return The collector used for search
 */
private Collector buildAndRunCollectorChain(QueryResult qr, Query query, Collector collector, QueryCommand cmd,
    DelegatingCollector postFilter) throws IOException {

  EarlyTerminatingSortingCollector earlyTerminatingSortingCollector = null;
  if (cmd.getSegmentTerminateEarly()) {
    final Sort cmdSort = cmd.getSort();
    final int cmdLen = cmd.getLen();
    final Sort mergeSort = core.getSolrCoreState().getMergePolicySort();

    if (cmdSort == null || cmdLen <= 0 || mergeSort == null ||
        !EarlyTerminatingSortingCollector.canEarlyTerminate(cmdSort, mergeSort)) {
      log.warn("unsupported combination: segmentTerminateEarly=true cmdSort={} cmdLen={} mergeSort={}", cmdSort, cmdLen, mergeSort);
    } else {
      collector = earlyTerminatingSortingCollector = new EarlyTerminatingSortingCollector(collector, cmdSort, cmd.getLen());
    }
  }

  final boolean terminateEarly = cmd.getTerminateEarly();
  if (terminateEarly) {
    collector = new EarlyTerminatingCollector(collector, cmd.getLen());
  }

  final long timeAllowed = cmd.getTimeAllowed();
  if (timeAllowed > 0) {
    collector = new TimeLimitingCollector(collector, TimeLimitingCollector.getGlobalCounter(), timeAllowed);
  }

  if (postFilter != null) {
    postFilter.setLastDelegate(collector);
    collector = postFilter;
  }

  try {
    super.search(query, collector);
  } catch (TimeLimitingCollector.TimeExceededException | ExitableDirectoryReader.ExitingReaderException x) {
    log.warn("Query: [{}]; {}", query, x.getMessage());
    qr.setPartialResults(true);
  } catch (EarlyTerminatingCollectorException etce) {
    if (collector instanceof DelegatingCollector) {
      ((DelegatingCollector) collector).finish();
    }
    throw etce;
  } finally {
    if (earlyTerminatingSortingCollector != null) {
      qr.setSegmentTerminatedEarly(earlyTerminatingSortingCollector.terminatedEarly());
    }
  }
  if (collector instanceof DelegatingCollector) {
    ((DelegatingCollector) collector).finish();
  }
  return collector;
}
 
源代码6 项目: mtas   文件: MtasSolrSearchComponent.java
@Override
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
	 // System.out
	 // .println(System.nanoTime() + " - " + Thread.currentThread().getId()
	 // + " - " + rb.req.getParams().getBool(ShardParams.IS_SHARD, false)
	 // + " MODIFY REQUEST " + rb.stage + " " + rb.req.getParamString());
	MtasSolrStatus solrStatus = Objects
			.requireNonNull((MtasSolrStatus) rb.req.getContext().get(MtasSolrStatus.class), "couldn't find status");
	solrStatus.setStage(rb.stage);
	try {
		if (sreq.params.getBool(PARAM_MTAS, false)) {
			if (sreq.params.getBool(MtasSolrComponentStatus.PARAM_MTAS_STATUS, false)) {
				searchStatus.modifyRequest(rb, who, sreq);
			} else if (requestHandler != null) {
				sreq.params.add(MtasSolrComponentStatus.PARAM_MTAS_STATUS, CommonParams.TRUE);
			}
			if (requestHandler != null) {
				sreq.params.add(MtasSolrComponentStatus.PARAM_MTAS_STATUS + "."
						+ MtasSolrComponentStatus.NAME_MTAS_STATUS_KEY, solrStatus.shardKey(rb.stage));
			}
			if (sreq.params.getBool(MtasSolrComponentVersion.PARAM_MTAS_VERSION, false)) {
				searchVersion.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {
				searchStats.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {
				searchTermvector.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX, false)) {
				searchPrefix.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {
				searchFacet.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {
				searchCollection.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {
				searchGroup.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentList.PARAM_MTAS_LIST, false)) {
				searchList.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {
				searchDocument.modifyRequest(rb, who, sreq);
			}
			if (sreq.params.getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC, false)) {
				searchKwic.modifyRequest(rb, who, sreq);
			}
		}
	} catch (ExitableDirectoryReader.ExitingReaderException e) {
		solrStatus.setError(e.getMessage());
	}
}
 
源代码7 项目: mtas   文件: MtasSolrSearchComponent.java
@Override
public void finishStage(ResponseBuilder rb) {
	 // System.out
	 // .println(System.nanoTime() + " - " + Thread.currentThread().getId()
	 //  + " - " + rb.req.getParams().getBool(ShardParams.IS_SHARD, false)
	 // + " FINISHRESPONSES " + rb.stage + " " + rb.req.getParamString());
	MtasSolrStatus solrStatus = Objects
			.requireNonNull((MtasSolrStatus) rb.req.getContext().get(MtasSolrStatus.class), "couldn't find status");
	solrStatus.setStage(rb.stage);
	try {
		if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {
			Status status = solrStatus.status();
			if (status.numberDocumentsFound == null) {
				status.numberDocumentsFound = rb.getNumberDocumentsFound();
			}
			// try to finish status from get fields stage
		} else if (rb.stage >= ResponseBuilder.STAGE_GET_FIELDS) {
			finishStatus(solrStatus);
		}
		if (rb.req.getParams().getBool(PARAM_MTAS, false)) {
			if (rb.req.getParams().getBool(MtasSolrComponentVersion.PARAM_MTAS_VERSION, false)) {
				searchVersion.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {
				searchStats.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {
				searchTermvector.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX, false)) {
				searchPrefix.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {
				searchFacet.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {
				searchCollection.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {
				searchGroup.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentList.PARAM_MTAS_LIST, false)) {
				searchList.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {
				searchDocument.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC, false)) {
				searchKwic.finishStage(rb);
			}
			mtasSolrResultMerge.merge(rb);
		}
	} catch (ExitableDirectoryReader.ExitingReaderException e) {
		solrStatus.setError(e.getMessage());
	}
}
 
 类所在包
 同包方法