Search in sources :

Example 11 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project ORCID-Source by ORCID.

the class SolrDaoImpl method findByOrcidAsReader.

@Override
public Reader findByOrcidAsReader(String orcid) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORCID + ":\"" + orcid + "\"").setFields(SCORE, ORCID, PUBLIC_PROFILE);
    query.add("wt", "orcidProfile");
    try {
        QueryResponse queryResponse = solrServerForStreaming.query(query);
        InputStream inputStream = (InputStream) queryResponse.getResponse().get("stream");
        return new InputStreamReader(inputStream, "UTF-8");
    } catch (SolrServerException | SolrException e) {
        String errorMessage = MessageFormat.format("Error when attempting to retrieve stream for orcid {0}", new Object[] { orcid });
        throw new NonTransientDataAccessResourceException(errorMessage, e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrException(org.apache.solr.common.SolrException)

Example 12 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project ORCID-Source by ORCID.

the class SolrDaoImpl method retrieveLastModified.

@Override
public Date retrieveLastModified(String orcid) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORCID + ":\"" + orcid + "\"");
    query.setFields(PROFILE_LAST_MODIFIED_DATE);
    try {
        QueryResponse response = solrServer.query(query);
        List<SolrDocument> results = response.getResults();
        if (results.isEmpty()) {
            return null;
        } else {
            return (Date) results.get(0).getFieldValue(PROFILE_LAST_MODIFIED_DATE);
        }
    } catch (SolrServerException e) {
        throw new NonTransientDataAccessResourceException("Error retrieving last modified date from SOLR Server", e);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) SolrDocument(org.apache.solr.common.SolrDocument) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Date(java.util.Date)

Example 13 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project incubator-atlas by apache.

the class Solr5Index method query.

@Override
public Iterable<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
    List<RawQuery.Result<String>> result;
    String collection = query.getStore();
    String keyIdField = getKeyFieldId(collection);
    SolrQuery solrQuery = new SolrQuery(query.getQuery()).addField(keyIdField).setIncludeScore(true).setStart(query.getOffset()).setRows(query.hasLimit() ? query.getLimit() : maxResults);
    try {
        QueryResponse response = solrClient.query(collection, solrQuery);
        if (logger.isDebugEnabled())
            logger.debug("Executed query [{}] in {} ms", query.getQuery(), response.getElapsedTime());
        int totalHits = response.getResults().size();
        if (!query.hasLimit() && totalHits >= maxResults) {
            logger.warn("Query result set truncated to first [{}] elements for query: {}", maxResults, query);
        }
        result = new ArrayList<>(totalHits);
        for (SolrDocument hit : response.getResults()) {
            double score = Double.parseDouble(hit.getFieldValue("score").toString());
            result.add(new RawQuery.Result<>(hit.getFieldValue(keyIdField).toString(), score));
        }
    } catch (IOException e) {
        logger.error("Query did not complete : ", e);
        throw new PermanentBackendException(e);
    } catch (SolrServerException e) {
        logger.error("Unable to query Solr index.", e);
        throw new PermanentBackendException(e);
    }
    return result;
}
Also used : PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) RawQuery(com.thinkaurelius.titan.diskstorage.indexing.RawQuery)

Example 14 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project jackrabbit-oak by apache.

the class SolrIndexEditorIT method testAddSomeNodes.

@Test
public void testAddSomeNodes() throws Exception {
    Root r = createRoot();
    r.getTree("/").addChild("a").addChild("b").addChild("doc1").setProperty("text", "hit that hot hat tattoo");
    r.getTree("/").getChild("a").addChild("c").addChild("doc2").setProperty("text", "it hits hot hats");
    r.getTree("/").getChild("a").getChild("b").addChild("doc3").setProperty("text", "tattoos hate hot hits");
    r.getTree("/").getChild("a").getChild("b").addChild("doc4").setProperty("text", "hats tattoos hit hot");
    r.commit();
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    QueryResponse queryResponse = server.query(query);
    assertTrue("no documents were indexed", queryResponse.getResults().size() > 0);
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrBaseTest(org.apache.jackrabbit.oak.plugins.index.solr.SolrBaseTest) Test(org.junit.Test)

Example 15 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project jackrabbit-oak by apache.

the class SolrIndexEditorTest method testIndexedProperties.

@Test
public void testIndexedProperties() throws Exception {
    SolrServer solrServer = TestUtils.createSolrServer();
    OakSolrConfiguration configuration = TestUtils.getTestConfiguration();
    IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
    SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
    NodeState before = mock(NodeState.class);
    NodeState after = mock(NodeState.class);
    Iterable properties = new Iterable<PropertyState>() {

        @Override
        public Iterator<PropertyState> iterator() {
            return Arrays.asList(PropertyStates.createProperty("foo1", "bar")).iterator();
        }
    };
    when(after.getProperties()).thenReturn(properties);
    solrIndexEditor.leave(before, after);
    QueryResponse queryResponse = solrServer.query(new SolrQuery("foo1:*"));
    assertEquals(1, queryResponse.getResults().getNumFound());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) SolrServer(org.apache.solr.client.solrj.SolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

SolrQuery (org.apache.solr.client.solrj.SolrQuery)316 Test (org.junit.Test)174 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)123 SolrInputDocument (org.apache.solr.common.SolrInputDocument)52 SolrServerException (org.apache.solr.client.solrj.SolrServerException)50 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)45 SolrDocument (org.apache.solr.common.SolrDocument)45 ArrayList (java.util.ArrayList)44 IOException (java.io.IOException)33 SolrDocumentList (org.apache.solr.common.SolrDocumentList)33 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)32 SolrClient (org.apache.solr.client.solrj.SolrClient)27 LinearModel (org.apache.solr.ltr.model.LinearModel)24 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)23 Replica (org.apache.solr.common.cloud.Replica)23 Slice (org.apache.solr.common.cloud.Slice)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)21 Map (java.util.Map)20 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 SolrException (org.apache.solr.common.SolrException)18