Search in sources :

Example 81 with SolrServerException

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

Example 82 with SolrServerException

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();
    }
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) MalformedURLException(java.net.MalformedURLException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 83 with SolrServerException

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);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException)

Example 84 with SolrServerException

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);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrServerException(org.apache.solr.client.solrj.SolrServerException) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) NoConverterException(org.apache.stanbol.entityhub.yard.solr.model.NoConverterException)

Example 85 with SolrServerException

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;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) YardException(org.apache.stanbol.entityhub.servicesapi.yard.YardException) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) PrivilegedActionException(java.security.PrivilegedActionException) 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