use of org.apache.solr.client.solrj.response.QueryResponse in project Xponents by OpenSextant.
the class TaxonMatcher method extractorImpl.
/**
* Implementation details -- use with or without the formal ID/buffer
* pairing.
*
* @param id
* doc id
* @param buf
* input text
* @return list of matches
* @throws ExtractionException
*/
private List<TextMatch> extractorImpl(String id, String buf) throws ExtractionException {
List<TextMatch> matches = new ArrayList<TextMatch>();
String docid = (id != null ? id : NO_DOC_ID);
Map<Integer, Object> beanMap = new HashMap<Integer, Object>(100);
QueryResponse response = tagTextCallSolrTagger(buf, docid, beanMap);
@SuppressWarnings("unchecked") List<NamedList<?>> tags = (List<NamedList<?>>) response.getResponse().get("tags");
log.debug("TAGS SIZE = {}", tags.size());
/*
* Retrieve all offsets into a long list.
*/
TaxonMatch m = null;
// int x1 = -1, x2 = -1;
int tag_count = 0;
String id_prefix = docid + "#";
for (NamedList<?> tag : tags) {
m = new TaxonMatch();
m.start = ((Integer) tag.get("startOffset")).intValue();
// +1 char after
m.end = ((Integer) tag.get("endOffset")).intValue();
// last matched
// m.pattern_id = "taxtag";
++tag_count;
m.match_id = id_prefix + tag_count;
// m.setText((String) tag.get("matchText")); // Not reliable.
// matchText can be null.
m.setText(buf.substring(m.start, m.end));
if (TextUtils.countFormattingSpace(m.getText()) > 1) {
// Phrase with a single TAB is okay
continue;
}
@SuppressWarnings("unchecked") List<Integer> taxonIDs = (List<Integer>) tag.get("ids");
for (Integer solrId : taxonIDs) {
Object refData = beanMap.get(solrId);
if (refData == null) {
continue;
}
/*
* Filter out non-Acronyms. e.g., 'who' is not a match for 'WHO'
*/
Taxon tx = (Taxon) refData;
if (this.filterNonAcronyms) {
if (tx.isAcronym && !m.isUpper()) {
continue;
}
}
m.addTaxon(tx);
}
//
if (m.hasTaxons()) {
matches.add(m);
}
}
log.debug("FOUND LABELS count={}", matches.size());
return matches;
}
use of org.apache.solr.client.solrj.response.QueryResponse in project Xponents by OpenSextant.
the class SolrProxy method searchGazetteer.
/**
* Search an OpenSextant solr gazetteer.
*
* @param index solr server handle
* @param qparams search parameters
* @return list of places
* @throws SolrServerException on err
*/
public static List<Place> searchGazetteer(SolrServer index, SolrParams qparams) throws SolrServerException {
QueryResponse response = index.query(qparams, SolrRequest.METHOD.GET);
List<Place> places = new ArrayList<>();
SolrDocumentList docList = response.getResults();
for (SolrDocument solrDoc : docList) {
places.add(SolrProxy.createPlace(solrDoc));
}
return places;
}
use of org.apache.solr.client.solrj.response.QueryResponse 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.response.QueryResponse 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.response.QueryResponse 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