use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project Solbase by Photobucket.
the class SolbaseIndexWriter method main.
public static void main(String[] args) {
try {
@SuppressWarnings("deprecation") CommonsHttpSolrServer // using seperate connector to leverage different http thread pool for updates
solbaseServer = new CommonsHttpSolrServer("http://den2sch21:8080/solbase/pbimages~4");
/*
doc.addField("docId", docNumber);
doc.addField("global_uniq_id", globalId);
doc.addField("title", "tom");
doc.addField("description", "Uploaded with Snapbucket");
doc.addField("tags", "Snapbucket");
doc.addField("path", "/albums/tt262/koh_tester/309AB021-orig.jpg");
doc.addField("subdomain", "i618");
doc.addField("lastModified", new Integer(SolbaseUtil.getEpochSinceSolbase(System.currentTimeMillis() / 60000)).toString());
doc.addField("media_type", new Integer(1).toString());
doc.addField("total_view_count", new Long(10).toString());
doc.addField("sevendays_view_count", new Integer(5).toString());
doc.addField("total_likes_count", new Long(5).toString());
doc.addField("sevendays_likes_count", new Integer(1).toString());
doc.addField("total_comments_count", new Long(5).toString());
doc.addField("sevendays_comments_count", new Integer(1).toString());
doc.addField("contents", "audi tom solbase Uploaded with Snapbucket ");
// whether we want to store to hbase or not
doc.addField("updateStore", true);
solbaseServer.add(doc);
*/
// for delete only
List<String> ids = new ArrayList<String>();
// term vector didn't get deleted doc id
ids.add(127995479 + "");
// term vector did get deleted doc id
ids.add(134876977 + "");
solbaseServer.deleteById(ids, true);
} catch (MalformedURLException e) {
} catch (SolrServerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project platformlayer by platformlayer.
the class ITSolrService method testSolrCustomField.
private void testSolrCustomField(String url, String field) throws SolrServerException, IOException {
CommonsHttpSolrServer client = new CommonsHttpSolrServer(url);
int docCount = 10;
List<String> fieldValues = Lists.newArrayList();
// Add some documents
{
for (int i = 0; i < docCount; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
doc.addField("value_i", i);
String fieldValue = random.randomText(40, 2000);
doc.addField(field, fieldValue);
fieldValues.add(fieldValue);
client.add(doc);
}
client.commit();
}
// Query the documents
{
SolrQuery query = new SolrQuery();
query.setQuery("value_i:[* TO 9]");
query.addSortField("value_i", SolrQuery.ORDER.asc);
query.setRows(Integer.MAX_VALUE);
QueryResponse response = client.query(query);
SolrDocumentList results = response.getResults();
Assert.assertEquals(results.getNumFound(), 10);
for (int i = 0; i < results.size(); i++) {
SolrDocument doc = results.get(i);
int docId = i;
Assert.assertEquals(doc.get("id"), String.valueOf(docId));
Assert.assertEquals(doc.get("value_i"), docId);
Assert.assertEquals(doc.get(field), fieldValues.get(i));
}
}
}
use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project platformlayer by platformlayer.
the class ITSolrService method testSolr.
private void testSolr(String url) throws SolrServerException, IOException {
CommonsHttpSolrServer client = new CommonsHttpSolrServer(url);
int docCount = 1000;
// Add some documents
{
for (int i = 0; i < docCount; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
doc.addField("name_t", "document" + i);
doc.addField("value_i", i);
doc.addField("units_i", i % 10);
doc.addField("content_t", random.randomText(40, 2000));
client.add(doc);
}
client.commit();
}
// Query the documents
{
SolrQuery query = new SolrQuery();
query.setQuery("units_i:2");
query.addSortField("value_i", SolrQuery.ORDER.asc);
query.setRows(Integer.MAX_VALUE);
QueryResponse response = client.query(query);
SolrDocumentList results = response.getResults();
Assert.assertEquals(results.getNumFound(), docCount / 10);
for (int i = 0; i < results.size(); i++) {
SolrDocument doc = results.get(i);
int docId = (i * 10) + 2;
Assert.assertEquals(doc.get("id"), String.valueOf(docId));
Assert.assertEquals(doc.get("units_i"), 2);
Assert.assertEquals(doc.get("name_t"), "document" + docId);
}
}
}
use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project opencast by opencast.
the class SolrServerFactory method newRemoteInstance.
/**
* Constructor. Prepares solr connection.
*
* @param url
* the connection url to the solr server
*/
public static SolrServer newRemoteInstance(URL url) {
try {
CommonsHttpSolrServer server = new CommonsHttpSolrServer(url);
server.setSoTimeout(5000);
server.setConnectionTimeout(5000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
// defaults to false
server.setFollowRedirects(false);
server.setAllowCompression(true);
// defaults to 0. > 1 not recommended.
server.setMaxRetries(1);
// binary parser is used by default
server.setParser(new XMLResponseParser());
return server;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project play-cookbook by spinscale.
the class SolrSearchTest method setup.
@Before
public void setup() throws Exception {
Fixtures.deleteAllModels();
server = new CommonsHttpSolrServer("http://localhost:8983/solr");
server.setRequestWriter(new BinaryRequestWriter());
clearSolrServerIndex();
Fixtures.loadModels("test-data.yml");
}
Aggregations