use of org.apache.solr.client.solrj.SolrServerException in project beam by apache.
the class SolrIOTestUtils method clearCollection.
/**
* Clear given collection.
*/
static void clearCollection(String collection, AuthorizedSolrClient client) throws IOException {
try {
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.setAction(UpdateRequest.ACTION.COMMIT, true, true);
updateRequest.deleteByQuery("*:*");
client.process(collection, updateRequest);
} catch (SolrServerException e) {
throw new IOException(e);
}
}
use of org.apache.solr.client.solrj.SolrServerException 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.SolrServerException in project stanbol by apache.
the class SolrFieldMapper method getSolrDocument.
/**
* Getter for a SolrDocument based on the ID. Used to load the config from the index.
*
* @param inputDoc
* the document to store
*/
protected SolrDocument getSolrDocument(String uri) throws SolrServerException, IOException {
if (server == null) {
return null;
}
final SolrQuery solrQuery = new SolrQuery();
// select all fields
solrQuery.addField("*");
// we query for the id, there is only one result
solrQuery.setRows(1);
String queryString = String.format("%s:%s", this.getDocumentIdField(), SolrUtil.escapeSolrSpecialChars(uri));
solrQuery.setQuery(queryString);
QueryResponse queryResponse;
try {
queryResponse = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
public QueryResponse run() throws IOException, SolrServerException {
return server.query(solrQuery);
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof SolrServerException) {
throw (SolrServerException) e;
} else if (e instanceof IOException) {
throw (IOException) e;
} else {
throw RuntimeException.class.cast(e);
}
}
if (queryResponse.getResults().isEmpty()) {
return null;
} else {
return queryResponse.getResults().get(0);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project stanbol by apache.
the class SolrYard method getSolrDocument.
protected final SolrDocument getSolrDocument(String uri, Collection<String> fields) throws SolrServerException, IOException {
final SolrQuery solrQuery = new SolrQuery();
if (fields == null || fields.isEmpty()) {
// select all fields
solrQuery.addField("*");
} else {
for (String field : fields) {
if (field != null && !field.isEmpty()) {
solrQuery.addField(field);
}
}
}
// we query for the id, there is only one result
solrQuery.setRows(1);
String queryString = String.format("%s:\"%s\"", fieldMapper.getDocumentIdField(), SolrUtil.escapeSolrSpecialChars(uri));
solrQuery.setQuery(queryString);
QueryResponse queryResponse;
try {
queryResponse = AccessController.doPrivileged(new PrivilegedExceptionAction<QueryResponse>() {
public QueryResponse run() throws IOException, SolrServerException {
return server.query(solrQuery, METHOD.POST);
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof SolrServerException) {
throw (SolrServerException) e;
} else if (e instanceof IOException) {
throw (IOException) e;
} else {
throw RuntimeException.class.cast(e);
}
}
if (queryResponse.getResults().isEmpty()) {
return null;
} else {
return queryResponse.getResults().get(0);
}
}
use of org.apache.solr.client.solrj.SolrServerException in project stanbol by apache.
the class SolrYard method store.
@Override
public final Representation store(Representation representation) throws YardException, IllegalArgumentException {
log.debug("Store {}", representation != null ? representation.getId() : null);
if (representation == null) {
throw new IllegalArgumentException("The parsed Representation MUST NOT be NULL!");
}
long start = System.currentTimeMillis();
final SolrInputDocument inputDocument = createSolrInputDocument(representation);
long create = System.currentTimeMillis();
if (closed) {
log.warn("The SolrYard '{}' was already closed!", config.getName());
}
try {
final UpdateRequest update = new UpdateRequest();
if (!immediateCommit) {
update.setCommitWithin(commitWithin);
}
update.add(inputDocument);
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() throws IOException, SolrServerException {
update.process(server);
if (immediateCommit) {
server.commit();
}
// nothing to return
return null;
}
});
long stored = System.currentTimeMillis();
log.debug(" ... done [create={}ms|store={}ms|sum={}ms]", new Object[] { (create - start), (stored - create), (stored - start) });
} catch (PrivilegedActionException pae) {
if (pae.getException() instanceof SolrServerException) {
throw new YardException(String.format("Exception while adding Document to Solr", representation.getId()), pae.getException());
} else if (pae.getException() instanceof IOException) {
throw new YardException("Unable to access SolrServer", pae.getException());
} else {
throw RuntimeException.class.cast(pae.getException());
}
}
return representation;
}
Aggregations