org.apache.solr.client.solrj.SolrServer Java Examples

The following examples show how to use org.apache.solr.client.solrj.SolrServer. 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: AbstractSolrInputOperator.java    From attic-apex-malhar with Apache License 2.0 9 votes vote down vote up
@Override
public void emitTuples()
{
  SolrParams solrQueryParams = getQueryParams();
  try {
    SolrServer solrServer = solrServerConnector.getSolrServer();
    QueryResponse response = solrServer.query(solrQueryParams);
    SolrDocumentList queriedDocuments = response.getResults();
    for (SolrDocument solrDocument : queriedDocuments) {
      emitTuple(solrDocument);
      lastEmittedTuple = solrDocument;
      lastEmittedTimeStamp = System.currentTimeMillis();

      logger.debug("Emiting document: " + solrDocument.getFieldValue("name"));
    }
  } catch (SolrServerException ex) {
    throw new RuntimeException("Unable to fetch documents from Solr server", ex);
  }
}
 
Example #2
Source File: SolrWriter.java    From anthelion with Apache License 2.0 6 votes vote down vote up
void init(SolrServer server, JobConf job) throws IOException {
  solr = server;
  commitSize = job.getInt(SolrConstants.COMMIT_SIZE, 1000);
  solrMapping = SolrMappingReader.getInstance(job);
  delete = job.getBoolean(IndexerMapReduce.INDEXER_DELETE, false);
  // parse optional params
  params = new ModifiableSolrParams();
  String paramString = job.get(SolrConstants.PARAMS);
  if (paramString != null) {
    String[] values = paramString.split("&");
    for (String v : values) {
      String[] kv = v.split("=");
      if (kv.length < 2) {
        continue;
      }
      params.add(kv[0], kv[1]);
    }
  }
}
 
Example #3
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Test
public void weShouldBeAbleToPageResults() throws SolrServerException, IOException, BlurException, TException {
  String table = "weShouldBeAbleToPageResults";
  SolrServer server = createServerAndTableWithSimpleTestDoc(table);

  SolrQuery query = new SolrQuery("123");
  query.setFields("fam.value");
  QueryResponse response = server.query(query);

  assertEquals("We should get our doc back for a valid test.", 1l, response.getResults().getNumFound());

  SolrDocument docResult = response.getResults().get(0);

  assertEquals("123", docResult.getFieldValue("fam.value"));
  assertNull("We shouldn't get this one back since it wasnt in our fields.", docResult.getFieldValues("fam.mvf"));

  removeTable(table);
}
 
Example #4
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Test
public void fieldsRequestsShouldTurnIntoSelectors() throws Exception,
    TException {

  String table = "fieldsRequestsShouldTurnIntoSelectors";
  SolrServer server = TestTableCreator.newTable(table)
      .withRowCount(1).withRecordsPerRow(2)
      .withRecordColumns("fam.value", "fam.mvf").create();

  SolrQuery query = new SolrQuery("value0-0");
  query.setFields("fam.value");
  QueryResponse response = server.query(query);

  assertEquals("We should get our doc back for a valid test.", 1l, response.getResults().getNumFound());

  SolrDocument docResult = response.getResults().get(0);

  assertEquals("value0-0", docResult.getFieldValue("fam.value"));
  assertNull("We shouldn't get this one back since it wasnt in our fields.", docResult.getFieldValues("fam.mvf"));

  removeTable(table);
}
 
Example #5
Source File: ConfigAction.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String test() {
	try {
		if (StringUtils.isNotBlank(this.getProviderUrl())) {
			SolrServer httpSolrServer = new HttpSolrServer(this.getProviderUrl());
			SolrPingResponse ping = httpSolrServer.ping();
			String time = String.valueOf(ping.getElapsedTime());
			String[] args = {time};
			this.addActionMessage(this.getText("note.provider.success", args));
		}
	} catch (SolrServerException slr) {
		_logger.error("error in test", slr);
		this.addActionError(this.getText("error.connection"));
		return SUCCESS;
	} catch (Throwable t) {
		_logger.error("error in test", t);
		return FAILURE;
	}
	return SUCCESS;
}
 
Example #6
Source File: SolrCommandRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Manually purge the index to try again.
 * Since this cascade is currently ordered, can be used to purge before we load.
 * 
 * @param opts
 * @throws Exception
 */
@SuppressWarnings("deprecation")
@CLIMethod("--solr-purge")
public void purgeSolr(Opts opts) throws Exception  {

	// Check to see if the global url has been set.
	String url = sortOutSolrURL(globalSolrURL);				

	// Wipe out the solr index at url.
	SolrServer server = new CommonsHttpSolrServer(url);
	server.deleteByQuery("*:*");
	server.commit();

	// Probably worked, so let's destroy the log if there is one.
	if( globalSolrLogFile != null && globalSolrLogFile.exists() ){
		boolean yes_p = globalSolrLogFile.delete();
		if( yes_p ){
			LOG.info("Deleted GOlr load log file.");
		}else{
			// Nothing there, doing nothing.
		}
	}
	LOG.info("Purged: " + url);
}
 
Example #7
Source File: SolrTarget04.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private SolrServer getSolrClient() throws MalformedURLException {
  if(kerberosAuth) {
    // set kerberos before create SolrClient
    addSecurityProperties();
  }

  if (SolrInstanceAPIType.SINGLE_NODE.toString().equals(this.instanceType)) {
    HttpSolrServer httpSolrServer = new HttpSolrServer(this.solrURI);
    httpSolrServer.setConnectionTimeout(connectionTimeout);
    httpSolrServer.setSoTimeout(socketTimeout);
    return httpSolrServer;
  } else {
    CloudSolrServer cloudSolrClient = new CloudSolrServer(this.zookeeperConnect);
    cloudSolrClient.setDefaultCollection(this.defaultCollection);
    return cloudSolrClient;
  }
}
 
Example #8
Source File: TestSolr.java    From DistributedCrawler with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearch() throws SolrServerException{
	String url = "http://localhost:8888/solr";
	  SolrServer server = new HttpSolrServer(url);
	  SolrQuery query = new SolrQuery("火箭");
	  query.setStart(0);
	  query.setRows(100);
	   QueryResponse response = server.query(query);
	   SolrDocumentList docs = response.getResults();
	   System.out.println("文档个数:" + docs.getNumFound());
	   System.out.println("查询时间:" + response.getQTime());
	   for (SolrDocument doc : docs) {
	    System.out.println("id: " + doc.getFieldValue("id"));
	    System.out.println("title: " + doc.getFieldValue("title"));
	    System.out.println("contect: "+doc.getFieldValue("content"));
	   }
}
 
Example #9
Source File: Searcher.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected List<String> executeQuery(SolrQuery solrQuery) throws ApsSystemException {
  	List<String> contentsId = new ArrayList<String>();
  	try {
	HttpClient httpClient = new DefaultHttpClient();
	SolrServer solr = new HttpSolrServer(this.getSolrUrl(), httpClient, new XMLResponseParser());
	QueryResponse rsp = solr.query(solrQuery);
          SolrDocumentList solrDocumentList = rsp.getResults();
          for (SolrDocument doc : solrDocumentList) {
		String id = (String) doc.getFieldValue(CmsSearchEngineManager.CONTENT_ID_FIELD_NAME); //id is the uniqueKey field
              contentsId.add(id);
          }
  	} catch (SolrServerException e) {
	throw new ApsSystemException("Error on solr server", e);
} catch (Throwable t) {
  		throw new ApsSystemException("Error extracting response", t);
  	}
  	return contentsId;
  }
 
Example #10
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Test
public void weShouldBeAbleToDeleteARowByAListOfIds() throws Exception,
    TException {
  String table = "weShouldBeAbleToDeleteARowByAListOfIds";

  SolrServer server = TestTableCreator.newTable(table).withRowCount(20).withRecordsPerRow(1)
      .withRecordColumns("fam.value").create();

  assertTotalResults(table, "rowid:1", 1l);
  assertTotalResults(table, "rowid:2", 1l);
  List<String> ids = Lists.newArrayList("1", "2", "3", "4", "5");
  server.deleteById(ids);

  for (String id : ids) {
    assertTotalResults(table, "rowid:" + id, 0l);
  }

  removeTable(table);
}
 
Example #11
Source File: SolrIndexWriter.java    From nutch-htmlunit with Apache License 2.0 6 votes vote down vote up
void init(SolrServer server, JobConf job) throws IOException {
    solr = server;
    batchSize = job.getInt(SolrConstants.COMMIT_SIZE, 1000);
    solrMapping = SolrMappingReader.getInstance(job);
    delete = job.getBoolean(IndexerMapReduce.INDEXER_DELETE, false);
    // parse optional params
    params = new ModifiableSolrParams();
    String paramString = job.get(IndexerMapReduce.INDEXER_PARAMS);
    if (paramString != null) {
        String[] values = paramString.split("&");
        for (String v : values) {
            String[] kv = v.split("=");
            if (kv.length < 2) {
                continue;
            }
            params.add(kv[0], kv[1]);
        }
    }
}
 
Example #12
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
public SolrServer create() throws Exception {
  createTable(tableName);
  SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(), tableName);

  for (int i = 0; i < rows; i++) {
    SolrInputDocument parent = new SolrInputDocument();
    parent.addField(BlurConstants.ROW_ID, i);
    for (int j = 0; j < recordsPerRow; j++) {
      SolrInputDocument child = new SolrInputDocument();
      child.addField(BlurConstants.RECORD_ID, j);

      for (String colName : columns) {
        child.addField(colName, "value" + i + "-" + j);
      }
      parent.addChildDocument(child);
    }
    server.add(parent);
  }
  return server;
}
 
Example #13
Source File: ThothServers.java    From thoth with BSD 3-Clause Clear License 6 votes vote down vote up
public ArrayList<ServerDetail> getList(SolrServer realTimeThoth) throws SolrServerException {
  ArrayList<ServerDetail> serverDetails = new ArrayList<ServerDetail>();
  // Using HierarchicalFaceting to fetch server details .http://wiki.apache.org/solr/HierarchicalFaceting
  QueryResponse qr = realTimeThoth.query(new SolrQuery("*:*").addFacetPivotField(FACET_PIVOT_FIELDS).setRows(0).setFacetLimit(FACET_LIMIT));
  NamedList<List<PivotField>> pivots = qr.getFacetPivot();
  System.out.println("Found " + pivots.get(FACET_PIVOT_FIELDS).size()+" servers to monitor. Fetching information for these servers. Please wait");
  for (PivotField pivot: pivots.get(FACET_PIVOT_FIELDS)){
    String hostname = (String) pivot.getValue();
    for (PivotField pf: pivot.getPivot()){
      String coreName = (String) pf.getValue();
      ServerDetail detail = fetchServerDetails(hostname,coreName, realTimeThoth);
      if (detail != null) serverDetails.add(detail);
    }
  }
  return serverDetails;
}
 
Example #14
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Test
public void weShouldBeAbleToDeleteARowById() throws Exception,
    TException {
  String table = "weShouldBeAbleToDeleteARowById";

  SolrServer server = TestTableCreator.newTable(table).withRowCount(2).withRecordsPerRow(1)
      .withRecordColumns("fam.value").create();

  assertTotalResults(table, "rowid:0", 1l);
  assertTotalResults(table, "rowid:1", 1l);

  server.deleteById("1");

  assertTotalResults(table, "rowid:0", 1l);
  assertTotalResults(table, "rowid:1", 0l);

  removeTable(table);
}
 
Example #15
Source File: FullTaxonIntegrationRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
@Ignore("This test requires a missing resource.")
public void testLoadFullTaxon() throws Exception {
	ParserWrapper pw = new ParserWrapper();
	final OWLGraphWrapper g = pw.parseToOWLGraph(taxonFile);
	
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	GafSolrDocumentLoaderIntegrationRunner.gc();
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	
	ConfigManager configManager = new ConfigManager();
	configManager.add("src/test/resources/test-ont-config.yaml");
	FlexCollection c = new FlexCollection(configManager, g);
	
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	GafSolrDocumentLoaderIntegrationRunner.gc();
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	
	FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrServer)null, c) {

		@Override
		protected void addToServer(Collection<SolrInputDocument> docs)
				throws SolrServerException, IOException {
			solrCounter += docs.size();
			GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
			System.out.println("Cache size: "+g.getCurrentEdgesAdvancedCacheSize());
		}
		
	};
	loader.load();
	assertTrue(solrCounter > 0);
}
 
Example #16
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
private SolrServer createServerAndTableWithSimpleTestDoc(String table) throws BlurException, TException, IOException,
    SolrServerException {
  createTable(table);
  SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(), table);
  SolrInputDocument doc;

  doc = createSimpleTestDoc();

  server.add(doc);
  return server;
}
 
Example #17
Source File: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ModelAnnotationSolrDocumentLoader(SolrServer server, OWLOntology model, OWLReasoner r, String modelUrl, 
		Set<String> modelFilter, boolean skipDeprecatedModels, boolean skipTemplateModels) {
	super(server);
	this.model = model;
	this.reasoner = r;
	this.requiredModelStates = modelFilter;
	this.skipDeprecatedModels = skipDeprecatedModels;
	this.skipTemplateModels = skipTemplateModels;
	this.graph = new OWLGraphWrapper(model);
	this.modelUrl = modelUrl;
	current_doc_number = 0;
	OWLDataFactory df = graph.getDataFactory();
	partOf = OBOUpperVocabulary.BFO_part_of.getObjectProperty(df);
	occursIn = OBOUpperVocabulary.BFO_occurs_in.getObjectProperty(df);
	
	defaultClosureRelations = new ArrayList<String>(1);
	defaultClosureRelations.add(graph.getIdentifier(partOf));
	
	enabledBy = OBOUpperVocabulary.GOREL_enabled_by.getObjectProperty(df);
	
	title = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/title"));
	source = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/source"));
	contributor = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/contributor"));
	date = df.getOWLAnnotationProperty(IRI.create("http://purl.org/dc/elements/1.1/date"));
	evidence = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence"));
	modelState = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/modelstate"));
	comment = df.getRDFSComment();
	with = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence-with"));
	layoutHintX = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/hint/layout/x"));
	layoutHintY = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/hint/layout/y"));
	templatestate = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/templatestate"));
	
	displayLabelProp = df.getRDFSLabel();
	shortIdProp = df.getOWLAnnotationProperty(IRI.create(Obo2OWLConstants.OIOVOCAB_IRI_PREFIX+"id"));
	
	jsonProp = df.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/json-model"));
	
	bpSet = getAspect(graph, "biological_process");
}
 
Example #18
Source File: QuestionIndexProviderTest.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Test
public void should_build_null_question_index() throws Exception {
	Environment env = mock(Environment.class);
	when(env.get(eq("feature.solr"), anyString())).thenReturn("false");
	Instance<SolrServer> instance = mock(Instance.class);
	QuestionIndexProvider provider = new QuestionIndexProvider(env, instance);

	QuestionIndex build = provider.build();
	assertTrue(NullQuestionIndex.class.isInstance(build));
}
 
Example #19
Source File: QuestionIndexProviderTest.java    From mamute with Apache License 2.0 5 votes vote down vote up
@Test
public void should_build_solr_question_index() throws Exception {
	Environment env = mock(Environment.class);
	when(env.get(eq("feature.solr"), anyString())).thenReturn("true");
	Instance<SolrServer> instance = mock(Instance.class);
	Iterator<SolrServer> iterator = mock(Iterator.class);
	when(instance.iterator()).thenReturn(iterator);
	QuestionIndexProvider provider = new QuestionIndexProvider(env, instance);

	QuestionIndex build = provider.build();
	assertTrue(SolrQuestionIndex.class.isInstance(build));
}
 
Example #20
Source File: AddTestCase.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Setup fixture for this test case.
 * 
 * @throws Exception never, otherwise the corresponding test fails.
 */
@Before
public void setUp() throws Exception{
	dataset = mock(DatasetAccessor.class);
	solr = mock(SolrServer.class);
	solrdf = new SolRDF(dataset, "/sparql", solr);
	uri = new URI("http://org.example.blablabla").toString();
}
 
Example #21
Source File: SearchTestCase.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Setup fixture for this test case.
 * 
 * @throws Exception never, otherwise the corresponding test fails.
 */
@Before
public void setUp() throws Exception{
	dataset = mock(DatasetAccessor.class);
	solr = mock(SolrServer.class);
	solrdf = new SolRDF(dataset, "/sparql", solr);
	uri = new URI("http://org.example.blablabla").toString();
}
 
Example #22
Source File: ThothServers.java    From thoth with BSD 3-Clause Clear License 5 votes vote down vote up
private ServerDetail fetchServerDetails(String hostname, String coreName, SolrServer realTimeThoth) throws SolrServerException {
  System.out.println("Fetching server details for hostname("+hostname+") coreName("+coreName+")");
  QueryResponse qr = realTimeThoth.query(new SolrQuery("hostname_s:\"" + hostname + "\"" +" AND " + "coreName_s:\"" +coreName + "\" AND NOT exception_b:true AND NOT slowQuery_b:true").setRows(1));
  SolrDocumentList solrDocumentList = qr.getResults();
  ServerDetail sd = null;
  if (qr.getResults().getNumFound() > 0) {
    String pool = (String)solrDocumentList.get(0).getFieldValue(POOL);
    String port = solrDocumentList.get(0).getFieldValue(PORT).toString();
    sd = new ServerDetail(hostname, pool, port, coreName);
  }
  return sd;
}
 
Example #23
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Test
public void docShouldBeDiscoverableWithMultiValuedFields() throws SolrServerException, IOException, BlurException,
    TException {
  String table = "docShouldBeDiscoverableWithMultiValuedFields";
  createTable(table);
  SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(), table);
  SolrInputDocument doc = new SolrInputDocument();
  doc.addField("rowid", "1");

  SolrInputDocument child = new SolrInputDocument();
  child.addField("recordid", "1");
  child.addField("fam.value", "123");
  child.addField("fam.value", "124");

  doc.addChildDocument(child);

  server.add(doc);

  assertTotalResults(table, "fam.value:123", 1l);
  assertTotalResults(table, "fam.value:124", 1l);
  assertTotalResults(table, "fam.value:justincase", 0l);

  removeTable(table);
}
 
Example #24
Source File: GoLoaderIntegrationRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
@Ignore("This test requires a missing resource.")
public void testLoadGoTaxon() throws Exception {
	ParserWrapper pw = new ParserWrapper();
	pw.addIRIMapper(new CatalogXmlIRIMapper(catalogXml));
	OWLGraphWrapper g = pw.parseToOWLGraph(goFile);
	
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	GafSolrDocumentLoaderIntegrationRunner.gc();
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	
	ConfigManager configManager = new ConfigManager();
	configManager.add("src/test/resources/test-ont-config.yaml");
	
	StopWatch watch = new StopWatch();
	watch.start();
	FlexCollection c = new FlexCollection(configManager, g);
	
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	GafSolrDocumentLoaderIntegrationRunner.gc();
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	
	FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrServer)null, c) {

		@Override
		protected void addToServer(Collection<SolrInputDocument> docs)
				throws SolrServerException, IOException {
			solrCounter += docs.size();
		}
		
	};
	loader.load();
	watch.stop();
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	System.out.println("Loaded "+solrCounter+" Solr docs in "+watch);
	assertTrue(solrCounter > 0);
}
 
Example #25
Source File: MockModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public MockModelAnnotationSolrDocumentLoader(String golrUrl,
        OWLOntology model, OWLReasoner r, String modelUrl,
        Set<String> modelFilter, boolean skipDeprecatedModels,
        boolean skipTemplateModels) throws MalformedURLException {
    super((SolrServer)null, model, r, modelUrl, modelFilter, skipDeprecatedModels,
            skipTemplateModels);
    // TODO Auto-generated constructor stub
}
 
Example #26
Source File: MockModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public MockModelAnnotationSolrDocumentLoader(SolrServer server,
        OWLOntology model, OWLReasoner r, String modelUrl,
        Set<String> modelFilter, boolean skipDeprecatedModels,
        boolean skipTemplateModels) {
    super(server, model, r, modelUrl, modelFilter, skipDeprecatedModels,
            skipTemplateModels);
    // TODO Auto-generated constructor stub
}
 
Example #27
Source File: TestSolr.java    From DistributedCrawler with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws SolrServerException, IOException {
	String url = "http://localhost:8888/solr";
	SolrServer server = new HttpSolrServer(url);
	SolrInputDocument doc1 = new SolrInputDocument();
	doc1.addField("id", "1");
	doc1.addField("title", "习近平亲民广获赞誉 美媒称领导中共魅力攻势");
	doc1.addField("content", "最近一段时间,国家主席习近平排队吃包子、办公室发表新年贺词引起了广泛关注。人们发现,国家最高领导人吃的是寻常百姓饭,办公室里摆的也是家人照片。");
	server.add(doc1);
	server.commit();
}
 
Example #28
Source File: SolrEntityQueryMixin.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
public SolrDocumentList search( String queryString ) throws SolrServerException
{
    SolrServer server = solr.solrServer();

    NamedList<Object> list = new NamedList<>();

    list.add( "q", queryString );

    QueryResponse query = server.query( SolrParams.toSolrParams( list ) );
    return query.getResults();
}
 
Example #29
Source File: SolrDeleteDuplicates.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/** Return each index as a split. */
public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
  SolrServer solr = SolrUtils.getCommonsHttpSolrServer(job);

  final SolrQuery solrQuery = new SolrQuery(SOLR_GET_ALL_QUERY);
  solrQuery.setFields(SolrConstants.ID_FIELD);
  solrQuery.setRows(1);

  QueryResponse response;
  try {
    response = solr.query(solrQuery);
  } catch (final SolrServerException e) {
    throw new IOException(e);
  }

  int numResults = (int)response.getResults().getNumFound();
  int numDocsPerSplit = (numResults / numSplits); 
  int currentDoc = 0;
  SolrInputSplit[] splits = new SolrInputSplit[numSplits];
  for (int i = 0; i < numSplits - 1; i++) {
    splits[i] = new SolrInputSplit(currentDoc, numDocsPerSplit);
    currentDoc += numDocsPerSplit;
  }
  splits[splits.length - 1] = new SolrInputSplit(currentDoc, numResults - currentDoc);

  return splits;
}
 
Example #30
Source File: QuestionIndexProvider.java    From mamute with Apache License 2.0 4 votes vote down vote up
@Inject
public QuestionIndexProvider(Environment environment, Instance<SolrServer> server) {
	this.environment = environment;
	this.server = server;
}