Domanda

We are building a wrapper over Solr using SolrJ.

This wrapper will allow clients to specify a collection name and then interact with that collection for insert/update/query using SolrJ wrapper.

I have been able to do insert/update/query operations, but haven't been able to find any SolrJ API/Example to specify collection names.

Its essential to use SolrJ as clients do not want to write string manipulated Solr queries directly.

Also, we want to use collections so that every client has its own index and remains distinct from other clients' documents.

Can anyone point me to SolrJ collection example/API ?

È stato utile?

Soluzione

import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.common.SolrInputDocument;

CloudSolrServer server = new CloudSolrServer("localhost:9983");
server.setDefaultCollection("collection1");
SolrInputDocument doc = new SolrInputDocument();
doc.addField( "id", "1234");
doc.addField( "name", "A lovely summer holiday");
server.add(doc);
server.commit();

From Solj documentation : http://wiki.apache.org/solr/Solrj

Altri suggerimenti

For someone who is not clustering Solr (no ZooKeeper), just instantiate SolrServer like this:

SolrServer solr = new HttpSolrServer("http://localhost:8983/solr/myCollection");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top