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 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 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 lucene-solr by apache.
the class TestContentStreamDataSource method testSimple.
@Test
public void testSimple() throws Exception {
DirectXmlRequest req = new DirectXmlRequest("/dataimport", xml);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command", "full-import");
params.set("clean", "false");
req.setParams(params);
try (HttpSolrClient solrClient = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
solrClient.request(req);
ModifiableSolrParams qparams = new ModifiableSolrParams();
qparams.add("q", "*:*");
QueryResponse qres = solrClient.query(qparams);
SolrDocumentList results = qres.getResults();
assertEquals(2, results.getNumFound());
SolrDocument doc = results.get(0);
assertEquals("1", doc.getFieldValue("id"));
assertEquals("Hello C1", ((List) doc.getFieldValue("desc")).get(0));
}
}
Aggregations