Search in sources :

Example 26 with SolrServerException

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");
}
Also used : Random(java.util.Random) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Example 27 with SolrServerException

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;
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 28 with SolrServerException

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;
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) StringByteIterator(com.yahoo.ycsb.StringByteIterator) SolrDocumentList(org.apache.solr.common.SolrDocumentList) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 29 with SolrServerException

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;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 30 with SolrServerException

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;
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Aggregations

SolrServerException (org.apache.solr.client.solrj.SolrServerException)281 IOException (java.io.IOException)210 SolrQuery (org.apache.solr.client.solrj.SolrQuery)101 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)97 ArrayList (java.util.ArrayList)58 SolrException (org.apache.solr.common.SolrException)57 SolrDocument (org.apache.solr.common.SolrDocument)55 SolrInputDocument (org.apache.solr.common.SolrInputDocument)50 SolrDocumentList (org.apache.solr.common.SolrDocumentList)44 HashMap (java.util.HashMap)30 Map (java.util.Map)29 List (java.util.List)27 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)26 SolrClient (org.apache.solr.client.solrj.SolrClient)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)23 NamedList (org.apache.solr.common.util.NamedList)22 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)19 Date (java.util.Date)18 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)17 SolrParams (org.apache.solr.common.params.SolrParams)13