use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project play-cookbook by spinscale.
the class SolrPlugin method getSearchServer.
public static SolrServer getSearchServer() {
String url = Play.configuration.getProperty("solr.server", "http://localhost:8983/solr");
CommonsHttpSolrServer server = null;
try {
server = new CommonsHttpSolrServer(url);
server.setRequestWriter(new BinaryRequestWriter());
} catch (MalformedURLException e) {
Logger.error(e, "Problem creating solr server object: %s", e.getMessage());
}
return server;
}
use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project Solbase by Photobucket.
the class CSVFileImporter method process.
private static void process(String str, HTablePool hTablePool) {
HTableInterface idMapTable = hTablePool.getTable("DocKeyIdMap");
HTableInterface seqTable = hTablePool.getTable("Sequence");
try {
StringTokenizer tokenizer = new StringTokenizer(str, ",");
if (tokenizer.countTokens() == 9) {
String id = tokenizer.nextToken();
String cat = tokenizer.nextToken();
String name = tokenizer.nextToken();
float price = Float.parseFloat(tokenizer.nextToken());
String inStock = tokenizer.nextToken();
String author_t = tokenizer.nextToken();
String series_t = tokenizer.nextToken();
String sequence_i = tokenizer.nextToken();
String genre_s = tokenizer.nextToken();
Get get = new Get(Bytes.toBytes(id));
Result result = idMapTable.get(get);
byte[] docId = result.getValue(Bytes.toBytes("docId"), Bytes.toBytes(""));
int docNumber = 1;
SolrInputDocument doc = new SolrInputDocument();
if (docId != null) {
// we've indexed this doc previously
docNumber = Bytes.toInt(docId);
doc.addField("edit", true);
} else {
docNumber = new Long(seqTable.incrementColumnValue(Bytes.toBytes("sequence"), Bytes.toBytes("id"), Bytes.toBytes(""), 1, true)).intValue();
}
doc.addField("docId", docNumber);
doc.addField("global_uniq_id", id);
doc.addField("cat", cat);
doc.addField("name", name);
// Solbase currently do not support float embedded field comparison
doc.addField("price", new Integer((int) price).toString());
doc.addField("inStock", inStock);
doc.addField("author_t", author_t);
doc.addField("series_t", series_t);
doc.addField("sequence_i", sequence_i);
doc.addField("genre_s", genre_s);
// whether we want to store to hbase or not
doc.addField("updateStore", true);
CommonsHttpSolrServer solbaseServer = new CommonsHttpSolrServer("http://localhost:8080/solbase/books~0");
solbaseServer.add(doc);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
hTablePool.putTable(idMapTable);
}
}
use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project whirr by apache.
the class SolrServiceTest method testSolr.
@Test
public void testSolr() throws IOException, SolrServerException {
Set<Cluster.Instance> instances = cluster.getInstancesMatching(role(SOLR_ROLE));
for (Cluster.Instance instance : instances) {
String publicIp = instance.getPublicIp();
LOG.info("Adding a document to instance " + instance.getId() + " @ " + publicIp);
CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(String.format("http://%s:%s/solr/core0", instance.getPublicHostName(), SOLR_PORT));
SolrInputDocument doc = new SolrInputDocument();
doc.addField("name", "Apache Whirr");
doc.addField("inceptionYear", "2010");
solrServer.add(doc);
solrServer.commit();
LOG.info("Committed document to instance " + instance.getId() + " @ " + publicIp);
LOG.info("Performing a search on instance " + instance.getId() + " @ " + publicIp);
SolrQuery query = new SolrQuery("name:whirr");
QueryResponse response = solrServer.query(query);
SolrDocumentList results = response.getResults();
assertEquals("Search on instance " + instance.getId() + " did NOT return a document!", 1, results.size());
SolrDocument resultDoc = results.get(0);
assertEquals("name field on document of instance " + instance.getId() + " is incorrect", "Apache Whirr", resultDoc.get("name"));
}
}
Aggregations