use of org.apache.solr.client.solrj.response.QueryResponse in project camel by apache.
the class SolrUpdateTest method testInsertStreaming.
@Test
public void testInsertStreaming() throws Exception {
Exchange exchange = createExchangeWithBody(null);
exchange.getIn().setHeader(SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT_STREAMING);
exchange.getIn().setHeader("SolrField.id", "MA147LL/A");
template.send("direct:start", exchange);
Thread.sleep(500);
solrCommit();
QueryResponse response = executeSolrQuery("id:MA147LL/A");
assertEquals(0, response.getStatus());
assertEquals(1, response.getResults().getNumFound());
}
use of org.apache.solr.client.solrj.response.QueryResponse in project camel by apache.
the class SolrUpdateTest method testInsertSolrInputDocumentAsXMLWithAddRoot.
@Test
public void testInsertSolrInputDocumentAsXMLWithAddRoot() throws Exception {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "MA147LL/A", 1.0f);
String docAsXml = "<add>" + ClientUtils.toXML(doc) + "</add>";
template.sendBodyAndHeader("direct:start", docAsXml, SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
solrCommit();
QueryResponse response = executeSolrQuery("id:MA147LL/A");
assertEquals(0, response.getStatus());
assertEquals(1, response.getResults().getNumFound());
}
use of org.apache.solr.client.solrj.response.QueryResponse in project camel by apache.
the class SolrUpdateTest method indexPDFDocumentToExtractingRequestHandler.
@Test
public void indexPDFDocumentToExtractingRequestHandler() throws Exception {
solrEndpoint.setRequestHandler("/update/extract");
Exchange exchange = createExchangeWithBody(new File("src/test/resources/data/tutorial.pdf"));
exchange.getIn().setHeader(SolrConstants.OPERATION, SolrConstants.OPERATION_INSERT);
exchange.getIn().setHeader("SolrParam.literal.id", "tutorial.pdf");
template.send("direct:start", exchange);
solrCommit();
QueryResponse response = executeSolrQuery("*:*");
assertEquals(0, response.getStatus());
assertEquals(1, response.getResults().getNumFound());
SolrDocument doc = response.getResults().get(0);
assertEquals("Solr", doc.getFieldValue("subject"));
assertEquals("tutorial.pdf", doc.getFieldValue("id"));
assertEquals(Arrays.asList("application/pdf"), doc.getFieldValue("content_type"));
}
use of org.apache.solr.client.solrj.response.QueryResponse in project titan by thinkaurelius.
the class SolrIndex 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<RawQuery.Result<String>>(totalHits);
for (SolrDocument hit : response.getResults()) {
double score = Double.parseDouble(hit.getFieldValue("score").toString());
result.add(new RawQuery.Result<String>(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.response.QueryResponse in project titan by thinkaurelius.
the class SolrIndex method query.
@Override
public List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
List<String> result;
String collection = query.getStore();
String keyIdField = getKeyFieldId(collection);
SolrQuery solrQuery = new SolrQuery("*:*");
String queryFilter = buildQueryFilter(query.getCondition(), informations.get(collection));
solrQuery.addFilterQuery(queryFilter);
if (!query.getOrder().isEmpty()) {
List<IndexQuery.OrderEntry> orders = query.getOrder();
for (IndexQuery.OrderEntry order1 : orders) {
String item = order1.getKey();
SolrQuery.ORDER order = order1.getOrder() == Order.ASC ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc;
solrQuery.addSort(new SolrQuery.SortClause(item, order));
}
}
solrQuery.setStart(0);
if (query.hasLimit()) {
solrQuery.setRows(query.getLimit());
} else {
solrQuery.setRows(maxResults);
}
try {
QueryResponse response = solrClient.query(collection, solrQuery);
if (logger.isDebugEnabled())
logger.debug("Executed query [{}] in {} ms", query.getCondition(), 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<String>(totalHits);
for (SolrDocument hit : response.getResults()) {
result.add(hit.getFieldValue(keyIdField).toString());
}
} 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;
}
Aggregations