use of org.apache.solr.client.solrj.SolrServerException in project lucene-solr by apache.
the class StoppableSearchThread method run.
@Override
public void run() {
Random random = LuceneTestCase.random();
int numSearches = 0;
while (!stop) {
numSearches++;
try {
//to come to the aid of their country.
cloudClient.query(new SolrQuery(QUERIES[random.nextInt(QUERIES.length)]));
} catch (Exception e) {
System.err.println("QUERY REQUEST FAILED:");
e.printStackTrace();
if (e instanceof SolrServerException) {
System.err.println("ROOT CAUSE:");
((SolrServerException) e).getRootCause().printStackTrace();
}
queryFails.incrementAndGet();
}
try {
Thread.sleep(random.nextInt(4000) + 300);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
log.info("num searches done:" + numSearches + " with " + queryFails + " fails");
}
use of org.apache.solr.client.solrj.SolrServerException in project jackrabbit-oak by apache.
the class SolrIndexEditor method childNodeDeleted.
@Override
public Editor childNodeDeleted(String name, NodeState before) throws CommitFailedException {
String path = partialEscape(PathUtils.concat(getPath(), name)).toString();
try {
String formattedQuery = String.format("%s:%s*", configuration.getPathField(), path);
if (log.isDebugEnabled()) {
log.debug("deleting by query {}", formattedQuery);
}
solrServer.deleteByQuery(formattedQuery);
updateCallback.indexUpdate();
} catch (SolrServerException e) {
throw new CommitFailedException("Solr", 5, "Failed to remove documents from Solr", e);
} catch (IOException e) {
throw new CommitFailedException("Solr", 6, "Failed to send data to Solr", e);
}
// no need to recurse down the removed subtree
return null;
}
use of org.apache.solr.client.solrj.SolrServerException in project YCSB by brianfrankcooper.
the class SolrClient method read.
/**
* Read a record from the database. Each field/value pair from the result will be stored in a
* HashMap.
*
* @param table
* The name of the table
* @param key
* The record key of the record to read.
* @param fields
* The list of fields to read, or null for all of them
* @param result
* A HashMap of field/value pairs for the result
* @return Zero on success, a non-zero error code on error or "not found".
*/
@Override
public Status read(String table, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
try {
Boolean returnFields = false;
String[] fieldList = null;
if (fields != null) {
returnFields = true;
fieldList = fields.toArray(new String[fields.size()]);
}
SolrQuery query = new SolrQuery();
query.setQuery("id:" + key);
if (returnFields) {
query.setFields(fieldList);
}
final QueryResponse response = client.query(table, query);
SolrDocumentList results = response.getResults();
if ((results != null) && (results.getNumFound() > 0)) {
for (String field : results.get(0).getFieldNames()) {
result.put(field, new StringByteIterator(String.valueOf(results.get(0).getFirstValue(field))));
}
}
return checkStatus(response.getStatus());
} catch (IOException | SolrServerException e) {
e.printStackTrace();
}
return Status.ERROR;
}
use of org.apache.solr.client.solrj.SolrServerException in project YCSB by brianfrankcooper.
the class SolrClient method insert.
/**
* Insert a record in the database. Any field/value pairs in the specified values HashMap will be
* written into the record with the specified record key.
*
* @param table
* The name of the table
* @param key
* The record key of the record to insert.
* @param values
* A HashMap of field/value pairs to insert in the record
* @return Zero on success, a non-zero error code on error. See this class's description for a
* discussion of error codes.
*/
@Override
public Status insert(String table, String key, HashMap<String, ByteIterator> values) {
try {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", key);
for (Entry<String, String> entry : StringByteIterator.getStringMap(values).entrySet()) {
doc.addField(entry.getKey(), entry.getValue());
}
UpdateResponse response;
if (batchMode) {
response = client.add(table, doc, commitTime);
} else {
response = client.add(table, doc);
client.commit(table);
}
return checkStatus(response.getStatus());
} catch (IOException | SolrServerException e) {
e.printStackTrace();
}
return Status.ERROR;
}
use of org.apache.solr.client.solrj.SolrServerException in project YCSB by brianfrankcooper.
the class SolrClient method delete.
/**
* Delete a record from the database.
*
* @param table
* The name of the table
* @param key
* The record key of the record to delete.
* @return Zero on success, a non-zero error code on error. See this class's description for a
* discussion of error codes.
*/
@Override
public Status delete(String table, String key) {
try {
UpdateResponse response;
if (batchMode) {
response = client.deleteById(table, key, commitTime);
} else {
response = client.deleteById(table, key);
client.commit(table);
}
return checkStatus(response.getStatus());
} catch (IOException | SolrServerException e) {
e.printStackTrace();
}
return Status.ERROR;
}
Aggregations