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);
}
}
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);
}
}
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;
}
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);
}
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());
}
Aggregations