use of org.apache.solr.common.SolrDocument in project ORCID-Source by ORCID.
the class SolrIndexUpdater method retrieveLastModified.
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.common.SolrDocument 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.common.SolrDocument in project Xponents by OpenSextant.
the class GazetteerMatcher method searchAdvanced.
/**
* This is a variation on SolrGazetteer.search(), just this creates ScoredPlace which is
* immediately usable with scoring and ranking matches. The score for a ScoredPlace is
* created when added to PlaceCandidate: a default score is created for the place.
*
* <pre>
* Usage:
* pc = PlaceCandidate();
* list = gaz.searchAdvanced("name:Boston", true) // solr fielded query used as-is.
* for ScoredPlace p: list:
* pc.addPlace( p )
* </pre>
*
* @param place
* the place string or text; or a Solr query
* @param as_solr
* the as_solr
* @param maxLen
* max length of gazetteer place names.
* @return places List of scoreable place entries
* @throws SolrServerException
* the solr server exception
*/
public List<ScoredPlace> searchAdvanced(String place, boolean as_solr, int maxLen) throws SolrServerException {
if (as_solr) {
params.set("q", place);
} else {
// Bare keyword query needs to be quoted as "word word word"
params.set("q", "\"" + place + "\"");
}
QueryResponse response = solr.getInternalSolrServer().query(params, SolrRequest.METHOD.GET);
List<ScoredPlace> places = new ArrayList<>();
for (SolrDocument solrDoc : response.getResults()) {
/*
* Length Filter. Alternative: store name as string in solr, vice full text field
*/
if (maxLen > 0) {
String nm = SolrProxy.getString(solrDoc, "name");
if (nm.length() > maxLen) {
continue;
}
}
places.add(createPlace(solrDoc));
}
return places;
}
use of org.apache.solr.common.SolrDocument 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.common.SolrDocument 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;
}
Aggregations