• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SolrQueryRequestBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.solr.request.SolrQueryRequestBase的典型用法代码示例。如果您正苦于以下问题:Java SolrQueryRequestBase类的具体用法?Java SolrQueryRequestBase怎么用?Java SolrQueryRequestBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SolrQueryRequestBase类属于org.apache.solr.request包,在下文中一共展示了SolrQueryRequestBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: newFrom

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
/**
 * Creates a new {@link SolrQueryRequest} from a given prototype and injects there a set of params. 
 * 
 * @param request the prototype {@link SolrQueryRequest}.
 * @param params the parameters that will be injected.
 * @return a {@link SolrQueryRequest} clone.
 */
public SolrQueryRequest newFrom(final SolrQueryRequest request, final SolrParams params) {
	return new SolrQueryRequestBase(
			request.getCore(), 
			new ModifiableSolrParams(params), 
			new RTimerTree()) {
		@Override
		public Map<Object, Object> getContext() {
			return request.getContext();
		}
		
		@Override
		public SolrIndexSearcher getSearcher() {
			return request.getSearcher();
		}
	};
}
 
开发者ID:spaziocodice,项目名称:invisible-queries-request-handler,代码行数:24,代码来源:InvisibleQueriesRequestHandler.java


示例2: handleSuggestionHitsRequest

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
public long handleSuggestionHitsRequest(ReSearcherRequestContext ctx, String query, Set<String> componentNames) throws Exception {
  ModifiableSolrParams params = new ModifiableSolrParams(ctx.getParams());
  params.set(CommonParams.ROWS, "0");
  for(String componentName : componentNames) {
    params.set(componentName, "false");
  }
  params.set(CommonParams.Q, query);

  SolrQueryRequest req = new SolrQueryRequestBase(ctx.getCore(), params) {};
  SolrQueryResponse rsp = new SolrQueryResponse();
  ResponseBuilder rb = new ResponseBuilder(req, rsp, ctx.getQueryOnlyComponents());
  
  try {
    handleSuggestionRequest(ctx, rb, ctx.getQueryOnlyComponents(), true);
  } finally {
    req.close();
  }
  
  return ReSearcherUtils.extractOriginalQueryHits(rb);
}
 
开发者ID:sematext,项目名称:solr-researcher,代码行数:21,代码来源:ReSearcherHandler.java


示例3: addDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
static void addDoc(String doc, String chain) throws Exception {
  Map<String, String[]> params = new HashMap<>();
  MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
  params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(),
      (SolrParams) mmparams) {
  };

  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init(null);
  ArrayList<ContentStream> streams = new ArrayList<>(2);
  streams.add(new ContentStreamBase.StringStream(doc));
  req.setContentStreams(streams);
  handler.handleRequestBody(req, new SolrQueryResponse());
  req.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:SignatureUpdateProcessorFactoryTest.java


示例4: addDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
private void addDoc(String doc) throws Exception {
  Map<String, String[]> params = new HashMap<>();
  MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
  params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" });
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(),
      (SolrParams) mmparams) {
  };

  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init(null);
  ArrayList<ContentStream> streams = new ArrayList<>(2);
  streams.add(new ContentStreamBase.StringStream(doc));
  req.setContentStreams(streams);
  handler.handleRequestBody(req, new SolrQueryResponse());
  req.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:UniqFieldsUpdateProcessorFactoryTest.java


示例5: addDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
static void addDoc(String doc, String chain) throws Exception {
  Map<String, String[]> params = new HashMap<String, String[]>();
  MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
  params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(),
      (SolrParams) mmparams) {
  };

  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init(null);
  ArrayList<ContentStream> streams = new ArrayList<ContentStream>(2);
  streams.add(new ContentStreamBase.StringStream(doc));
  req.setContentStreams(streams);
  handler.handleRequestBody(req, new SolrQueryResponse());
  req.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:SignatureUpdateProcessorFactoryTest.java


示例6: addDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
private void addDoc(String doc) throws Exception {
  Map<String, String[]> params = new HashMap<String, String[]>();
  MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
  params.put(UpdateParams.UPDATE_CHAIN, new String[] { "uniq-fields" });
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(),
      (SolrParams) mmparams) {
  };

  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init(null);
  ArrayList<ContentStream> streams = new ArrayList<ContentStream>(2);
  streams.add(new ContentStreamBase.StringStream(doc));
  req.setContentStreams(streams);
  handler.handleRequestBody(req, new SolrQueryResponse());
  req.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:UniqFieldsUpdateProcessorFactoryTest.java


示例7: handleSuggestionResponseRequest

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
public SolrQueryResponse handleSuggestionResponseRequest(ReSearcherRequestContext ctx, ModifiableSolrParams params, String componentName, List<SearchComponent> components) throws Exception {
  params.set(componentName, "false");

  SolrQueryRequest req = new SolrQueryRequestBase(ctx.getCore(), params) {};
  SolrQueryResponse rsp = new SolrQueryResponse();
  ResponseBuilder rb = new ResponseBuilder(req, rsp, components);
  
  try {
    handleSuggestionRequest(ctx, rb, components, false);
  } finally {
    req.close();
  }
  
  return rsp;
}
 
开发者ID:sematext,项目名称:solr-researcher,代码行数:16,代码来源:ReSearcherHandler.java


示例8: addDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
private void addDoc(String chain, String doc) throws Exception {
  Map<String, String[]> params = new HashMap<>();
  params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
  MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) {
  };

  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init(null);
  ArrayList<ContentStream> streams = new ArrayList<>(2);
  streams.add(new ContentStreamBase.StringStream(doc));
  req.setContentStreams(streams);
  handler.handleRequestBody(req, new SolrQueryResponse());
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:UIMAUpdateRequestProcessorTest.java


示例9: testCharsetInDocument

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
@Test
public void testCharsetInDocument() throws Exception {
  final byte[] xmlBytes = (
    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" +
    "<docs>\r\n" +
    " <doc>\r\n" +
    "  <field name=\"id\">Müller</field>\r\n" +
    " </doc>" +
    "</docs>"
  ).getBytes(StandardCharsets.ISO_8859_1);
  
  // we declare a content stream without charset:
  final ContentStream cs = new ByteStream(xmlBytes, "application/xml");
  
  ModifiableSolrParams params = new ModifiableSolrParams();
  SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
    @Override
    public Iterable<ContentStream> getContentStreams() {
      return Collections.singleton(cs);
    }
  };

  DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
  assertNotNull(request);
  final List<SolrInputDocument> documents = request.getDocuments();
  assertNotNull(documents);
  assertEquals(1, documents.size());
  SolrInputDocument doc = documents.get(0);
  assertEquals("Müller", doc.getField("id").getValue());
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:DocumentAnalysisRequestHandlerTest.java


示例10: testCharsetOutsideDocument

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
@Test
public void testCharsetOutsideDocument() throws Exception {
  final byte[] xmlBytes = (
    "<docs>\r\n" +
    " <doc>\r\n" +
    "  <field name=\"id\">Müller</field>\r\n" +
    " </doc>" +
    "</docs>"
  ).getBytes(StandardCharsets.ISO_8859_1);
  
  // we declare a content stream with charset:
  final ContentStream cs = new ByteStream(xmlBytes, "application/xml; charset=ISO-8859-1");
  
  ModifiableSolrParams params = new ModifiableSolrParams();
  SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
    @Override
    public Iterable<ContentStream> getContentStreams() {
      return Collections.singleton(cs);
    }
  };

  DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
  assertNotNull(request);
  final List<SolrInputDocument> documents = request.getDocuments();
  assertNotNull(documents);
  assertEquals(1, documents.size());
  SolrInputDocument doc = documents.get(0);
  assertEquals("Müller", doc.getField("id").getValue());
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:DocumentAnalysisRequestHandlerTest.java


示例11: addDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
private void addDoc(String chain, String doc) throws Exception {
  Map<String, String[]> params = new HashMap<String, String[]>();
  params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
  MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), (SolrParams) mmparams) {
  };

  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init(null);
  ArrayList<ContentStream> streams = new ArrayList<ContentStream>(2);
  streams.add(new ContentStreamBase.StringStream(doc));
  req.setContentStreams(streams);
  handler.handleRequestBody(req, new SolrQueryResponse());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:15,代码来源:UIMAUpdateRequestProcessorTest.java


示例12: testCharsetInDocument

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
@Test
public void testCharsetInDocument() throws Exception {
  final byte[] xmlBytes = (
    "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" +
    "<docs>\r\n" +
    " <doc>\r\n" +
    "  <field name=\"id\">Müller</field>\r\n" +
    " </doc>" +
    "</docs>"
  ).getBytes("ISO-8859-1");
  
  // we declare a content stream without charset:
  final ContentStream cs = new ByteStream(xmlBytes, "application/xml");
  
  ModifiableSolrParams params = new ModifiableSolrParams();
  SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
    @Override
    public Iterable<ContentStream> getContentStreams() {
      return Collections.singleton(cs);
    }
  };

  DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
  assertNotNull(request);
  final List<SolrInputDocument> documents = request.getDocuments();
  assertNotNull(documents);
  assertEquals(1, documents.size());
  SolrInputDocument doc = documents.get(0);
  assertEquals("Müller", doc.getField("id").getValue());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:31,代码来源:DocumentAnalysisRequestHandlerTest.java


示例13: testCharsetOutsideDocument

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
@Test
public void testCharsetOutsideDocument() throws Exception {
  final byte[] xmlBytes = (
    "<docs>\r\n" +
    " <doc>\r\n" +
    "  <field name=\"id\">Müller</field>\r\n" +
    " </doc>" +
    "</docs>"
  ).getBytes("ISO-8859-1");
  
  // we declare a content stream with charset:
  final ContentStream cs = new ByteStream(xmlBytes, "application/xml; charset=ISO-8859-1");
  
  ModifiableSolrParams params = new ModifiableSolrParams();
  SolrQueryRequest req = new SolrQueryRequestBase(h.getCore(), params) {
    @Override
    public Iterable<ContentStream> getContentStreams() {
      return Collections.singleton(cs);
    }
  };

  DocumentAnalysisRequest request = handler.resolveAnalysisRequest(req);
  assertNotNull(request);
  final List<SolrInputDocument> documents = request.getDocuments();
  assertNotNull(documents);
  assertEquals(1, documents.size());
  SolrInputDocument doc = documents.get(0);
  assertEquals("Müller", doc.getField("id").getValue());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:30,代码来源:DocumentAnalysisRequestHandlerTest.java


示例14: addDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
static void addDoc(String doc, String chain) throws Exception {
	Map<String, String[]> params = new HashMap<>();
	MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
	params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
	SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), mmparams) {
	};

	UpdateRequestHandler handler = new UpdateRequestHandler();
	handler.init(null);
	ArrayList<ContentStream> streams = new ArrayList<>(2);
	streams.add(new ContentStreamBase.StringStream(doc));
	req.setContentStreams(streams);
	handler.handleRequestBody(req, new SolrQueryResponse());
	req.close();
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:16,代码来源:OntologyUpdateProcessorFactoryTest.java


示例15: query

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
public static SolrQueryResponse query(SolrCore core, String handlerName, SolrParams params) {
  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequest req = new SolrQueryRequestBase(core, params) { };
  try {
    SolrRequestHandler handler = core.getRequestHandler(handlerName);
    core.execute(handler, req, rsp);
    return rsp;
  } finally {
    req.close();
  }
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:12,代码来源:BaseTestCase.java


示例16: verifyAuthorized

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
private void verifyAuthorized(String collection, String user) throws Exception {
  SolrQueryRequestBase req = new SolrQueryRequestBase(core, new MapSolrParams(new HashMap())) {};
  getProcessor(collection, user).processAdd(new AddUpdateCommand(req));
  getProcessor(collection, user).processDelete(new DeleteUpdateCommand(req));
  DeleteUpdateCommand deleteByQueryCommand = new DeleteUpdateCommand(req);
  deleteByQueryCommand.setQuery("*:*");
  getProcessor(collection, user).processDelete(deleteByQueryCommand);
  getProcessor(collection, user).processMergeIndexes(new MergeIndexesCommand(null, req));
  getProcessor(collection, user).processCommit(new CommitUpdateCommand(req, false));
  getProcessor(collection, user).processRollback(new RollbackUpdateCommand(req));
  getProcessor(collection, user).finish();
}
 
开发者ID:apache,项目名称:incubator-sentry,代码行数:13,代码来源:UpdateIndexAuthorizationProcessorTest.java


示例17: reqDoc

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
/** REMEMBER to close() the result req object. */
protected SolrQueryRequest reqDoc(String doc, SolrParams moreParams) {
  log.debug("Test doc: "+doc);
  SolrParams params = SolrParams.wrapDefaults(moreParams, baseParams);
  SolrQueryRequestBase req = new SolrQueryRequestBase(h.getCore(), params) {};
  Iterable<ContentStream> stream = Collections.singleton((ContentStream)new ContentStreamBase.StringStream(doc));
  req.setContentStreams(stream);
  return req;
}
 
开发者ID:OpenSextant,项目名称:SolrTextTagger,代码行数:10,代码来源:AbstractTaggerTest.java


示例18: testCommitWithin

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
public void testCommitWithin() throws Exception {
  SolrCore core = h.getCore();
  
  NewSearcherListener trigger = new NewSearcherListener();    
  core.registerNewSearcherListener(trigger);
  DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
  CommitTracker tracker = updater.commitTracker;
  tracker.setTimeUpperBound(0);
  tracker.setDocsUpperBound(-1);
  
  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init( null );
  
  MapSolrParams params = new MapSolrParams( new HashMap<String, String>() );
  
  // Add a single document with commitWithin == 2 second
  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {};
  req.setContentStreams( AutoCommitTest.toContentStreams(
    adoc(2000, "id", "529", "field_t", "what's inside?", "subject", "info"), null ) );
  trigger.reset();
  handler.handleRequest( req, rsp );

  // Check it isn't in the index
  assertQ("shouldn't find any", req("id:529") ,"//result[@numFound=0]" );
  
  // Wait longer than the commitWithin time
  assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));

  // Add one document without commitWithin
  req.setContentStreams( AutoCommitTest.toContentStreams(
      adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null ) );
    trigger.reset();
    handler.handleRequest( req, rsp );
    
  // Check it isn't in the index
  assertQ("shouldn't find any", req("id:530") ,"//result[@numFound=0]" );
  
  // Delete one document with commitWithin
  req.setContentStreams( AutoCommitTest.toContentStreams(
    delI("529", "commitWithin", "1000"), null ) );
  trigger.reset();
  handler.handleRequest( req, rsp );
    
  // Now make sure we can find it
  assertQ("should find one", req("id:529") ,"//result[@numFound=1]" );
  
  // Wait for the commit to happen
  assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
  
  // Now we shouldn't find it
  assertQ("should find none", req("id:529") ,"//result[@numFound=0]" );
  // ... but we should find the new one
  assertQ("should find one", req("id:530") ,"//result[@numFound=1]" );
  
  trigger.reset();
  
  // now make the call 10 times really fast and make sure it 
  // only commits once
  req.setContentStreams( AutoCommitTest.toContentStreams(
      adoc(2000, "id", "500" ), null ) );
  for( int i=0;i<10; i++ ) {
    handler.handleRequest( req, rsp );
  }
  assertQ("should not be there yet", req("id:500") ,"//result[@numFound=0]" );
  
  // the same for the delete
  req.setContentStreams( AutoCommitTest.toContentStreams(
      delI("530", "commitWithin", "1000"), null ) );
  for( int i=0;i<10; i++ ) {
    handler.handleRequest( req, rsp );
  }
  assertQ("should be there", req("id:530") ,"//result[@numFound=1]" );
  
  assertTrue("commitWithin failed to commit", trigger.waitForNewSearcher(30000));
  assertQ("should be there", req("id:500") ,"//result[@numFound=1]" );
  assertQ("should not be there", req("id:530") ,"//result[@numFound=0]" );
  
  assertEquals(3, tracker.getCommitCount());
}
 
开发者ID:europeana,项目名称:search,代码行数:81,代码来源:HardAutoCommitTest.java


示例19: testMaxDocs

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
public void testMaxDocs() throws Exception {
  SolrCore core = h.getCore();
  
  NewSearcherListener trigger = new NewSearcherListener();

  DirectUpdateHandler2 updateHandler = (DirectUpdateHandler2)core.getUpdateHandler();
  CommitTracker tracker = updateHandler.softCommitTracker;
  tracker.setTimeUpperBound(-1);
  tracker.setDocsUpperBound(14);
  core.registerNewSearcherListener(trigger);

  
  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init( null );
  
  MapSolrParams params = new MapSolrParams( new HashMap<String, String>() );
  
  // Add documents
  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {};
  for( int i=0; i<14; i++ ) {
    req.setContentStreams( toContentStreams(
      adoc("id", Integer.toString(i), "subject", "info" ), null ) );
    handler.handleRequest( req, rsp );
  }
  // It should not be there right away
  assertQ("shouldn't find any", req("id:1") ,"//result[@numFound=0]" );
  assertEquals( 0, tracker.getCommitCount());

  req.setContentStreams( toContentStreams(
      adoc("id", "14", "subject", "info" ), null ) );
  handler.handleRequest( req, rsp );

  assertTrue(trigger.waitForNewSearcher(15000));

  req.setContentStreams( toContentStreams(
      adoc("id", "15", "subject", "info" ), null ) );
  handler.handleRequest( req, rsp );
    
  // Now make sure we can find it
  assertQ("should find one", req("id:14") ,"//result[@numFound=1]" );
  assertEquals( 1, tracker.getCommitCount());
  // But not the one added afterward
  assertQ("should not find one", req("id:15") ,"//result[@numFound=0]" );
  assertEquals( 1, tracker.getCommitCount());
  
}
 
开发者ID:europeana,项目名称:search,代码行数:48,代码来源:AutoCommitTest.java


示例20: testMaxTime

import org.apache.solr.request.SolrQueryRequestBase; //导入依赖的package包/类
public void testMaxTime() throws Exception {
  SolrCore core = h.getCore();
  
  NewSearcherListener trigger = new NewSearcherListener();    
  core.registerNewSearcherListener(trigger);
  DirectUpdateHandler2 updater = (DirectUpdateHandler2) core.getUpdateHandler();
  CommitTracker tracker = updater.softCommitTracker;
  // too low of a number can cause a slow host to commit before the test code checks that it
  // isn't there... causing a failure at "shouldn't find any"
  tracker.setTimeUpperBound(1000);
  tracker.setDocsUpperBound(-1);
  // updater.commitCallbacks.add(trigger);
  
  UpdateRequestHandler handler = new UpdateRequestHandler();
  handler.init( null );
  
  MapSolrParams params = new MapSolrParams( new HashMap<String, String>() );
  
  // Add a single document
  SolrQueryResponse rsp = new SolrQueryResponse();
  SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {};
  req.setContentStreams( toContentStreams(
    adoc("id", "529", "field_t", "what's inside?", "subject", "info"), null ) );
  trigger.reset();
  handler.handleRequest( req, rsp );

  // Check it it is in the index
  assertQ("shouldn't find any", req("id:529") ,"//result[@numFound=0]" );

  // Wait longer than the autocommit time
  assertTrue(trigger.waitForNewSearcher(45000));
  trigger.reset();
  req.setContentStreams( toContentStreams(
    adoc("id", "530", "field_t", "what's inside?", "subject", "info"), null ) );
  handler.handleRequest( req, rsp );
    
  // Now make sure we can find it
  assertQ("should find one", req("id:529") ,"//result[@numFound=1]" );
  // But not this one
  assertQ("should find none", req("id:530") ,"//result[@numFound=0]" );
  
  // Delete the document
  assertU( delI("529") );
  assertQ("deleted, but should still be there", req("id:529") ,"//result[@numFound=1]" );
  // Wait longer than the autocommit time
  assertTrue(trigger.waitForNewSearcher(30000));
  trigger.reset();
  req.setContentStreams( toContentStreams(
    adoc("id", "550", "field_t", "what's inside?", "subject", "info"), null ) );
  handler.handleRequest( req, rsp );
  assertEquals( 2, tracker.getCommitCount() );
  assertQ("deleted and time has passed", req("id:529") ,"//result[@numFound=0]" );
  
  // now make the call 10 times really fast and make sure it 
  // only commits once
  req.setContentStreams( toContentStreams(
      adoc("id", "500" ), null ) );
  for( int i=0;i<10; i++ ) {
    handler.handleRequest( req, rsp );
  }
  assertQ("should not be there yet", req("id:500") ,"//result[@numFound=0]" );
  
  // Wait longer than the autocommit time
  assertTrue(trigger.waitForNewSearcher(45000));
  trigger.reset();
  
  req.setContentStreams( toContentStreams(
    adoc("id", "531", "field_t", "what's inside?", "subject", "info"), null ) );
  handler.handleRequest( req, rsp );
  assertEquals( 3, tracker.getCommitCount() );

  assertQ("now it should", req("id:500") ,"//result[@numFound=1]" );
}
 
开发者ID:europeana,项目名称:search,代码行数:74,代码来源:AutoCommitTest.java



注:本文中的org.apache.solr.request.SolrQueryRequestBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InternalException类代码示例发布时间:2022-05-22
下一篇:
Java UserRealm类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap