use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class SolrDaoImpl method querySolr.
private OrcidSolrResults querySolr(SolrQuery query) {
OrcidSolrResults orcidSolrResults = new OrcidSolrResults();
List<OrcidSolrResult> orcidSolrResultsList = new ArrayList<>();
orcidSolrResults.setResults(orcidSolrResultsList);
try {
QueryResponse queryResponse = solrServerReadOnly.query(query);
for (SolrDocument solrDocument : queryResponse.getResults()) {
OrcidSolrResult orcidSolrResult = new OrcidSolrResult();
orcidSolrResult.setRelevancyScore((Float) solrDocument.getFieldValue(SCORE));
orcidSolrResult.setOrcid((String) solrDocument.getFieldValue(ORCID));
orcidSolrResult.setPublicProfileMessage((String) solrDocument.getFieldValue(PUBLIC_PROFILE));
orcidSolrResultsList.add(orcidSolrResult);
}
orcidSolrResults.setNumFound(queryResponse.getResults().getNumFound());
} catch (SolrServerException se) {
throw new NonTransientDataAccessResourceException("Error retrieving from SOLR Server", se);
}
return orcidSolrResults;
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class SolrDaoImpl method findByOrcid.
@Override
public OrcidSolrResult findByOrcid(String orcid) {
OrcidSolrResult orcidSolrResult = null;
SolrQuery query = new SolrQuery();
query.setQuery(ORCID + ":\"" + orcid + "\"").setFields(SCORE, ORCID, PUBLIC_PROFILE);
try {
QueryResponse queryResponse = solrServerReadOnly.query(query);
if (!queryResponse.getResults().isEmpty()) {
SolrDocument solrDocument = queryResponse.getResults().get(0);
orcidSolrResult = new OrcidSolrResult();
orcidSolrResult.setRelevancyScore((Float) solrDocument.get(SCORE));
orcidSolrResult.setOrcid((String) solrDocument.get(ORCID));
orcidSolrResult.setPublicProfileMessage((String) solrDocument.getFieldValue(PUBLIC_PROFILE));
}
} catch (SolrServerException se) {
String errorMessage = MessageFormat.format("Error when attempting to retrieve orcid {0}", new Object[] { orcid });
throw new NonTransientDataAccessResourceException(errorMessage, se);
}
return orcidSolrResult;
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class OrcidSearchManagerImplTest method multipleResultsForQuery.
private OrcidSolrResults multipleResultsForQuery() {
OrcidSolrResults orcidSolrResults = new OrcidSolrResults();
List<OrcidSolrResult> resultsList = new ArrayList<>();
orcidSolrResults.setResults(resultsList);
resultsList.add(getSolrRes5678());
resultsList.add(getSolrRes6789());
orcidSolrResults.setNumFound(2);
return orcidSolrResults;
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class OrcidSearchManagerImplTest method getSolrRes5678.
private OrcidSolrResult getSolrRes5678() {
OrcidSolrResult solrResult = new OrcidSolrResult();
solrResult.setOrcid("5678");
solrResult.setRelevancyScore(new Float(37.2));
return solrResult;
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class SolrDaoTest method queryFieldWithBoostAndExclusions.
@Test
public void queryFieldWithBoostAndExclusions() throws Exception {
OrcidSolrDocument firstOrcidDoc = buildFirstOrcid();
firstOrcidDoc.setOrcid(firstOrcid);
firstOrcidDoc.setFamilyName("James");
OrcidSolrDocument secondOrcidDoc = buildSupplementaryOrcid();
secondOrcidDoc.setOrcid(secondOrcid);
secondOrcidDoc.setGivenNames("James");
OrcidSolrDocument thirdOrcidDoc = buildSupplementaryOrcid();
thirdOrcidDoc.setFamilyName("James");
thirdOrcidDoc.setOrcid(RandomStringUtils.randomAlphabetic(9));
persistOrcid(firstOrcidDoc);
persistOrcid(secondOrcidDoc);
persistOrcid(thirdOrcidDoc);
String familyNameGivenNameQuery = "{!edismax qf='family-name^1.0 given-names^2.0'}James";
List<OrcidSolrResult> solrResults = solrDao.findByDocumentCriteria(familyNameGivenNameQuery, null, null).getResults();
assertTrue(solrResults.size() == 3);
OrcidSolrResult givenNameMatch = solrResults.get(0);
assertTrue(secondOrcid.equals(givenNameMatch.getOrcid()) && givenNameMatch.getRelevancyScore() > 1);
OrcidSolrResult familyNameMatch1 = solrResults.get(1);
OrcidSolrResult familyNameMatch2 = solrResults.get(2);
assertTrue(familyNameMatch1.getRelevancyScore() < 1.0);
assertTrue(familyNameMatch2.getRelevancyScore() < 1.0);
String familyNameGivenNameQueryWithExclude = familyNameGivenNameQuery + " -orcid:" + thirdOrcidDoc.getOrcid();
solrResults = solrDao.findByDocumentCriteria(familyNameGivenNameQueryWithExclude, null, null).getResults();
assertTrue(solrResults.size() == 2);
givenNameMatch = solrResults.get(0);
assertTrue(givenNameMatch.getOrcid().equals(secondOrcid));
assertTrue(givenNameMatch.getRelevancyScore() > 1);
familyNameMatch1 = solrResults.get(1);
assertTrue(familyNameMatch1.getOrcid().equals(firstOrcid));
assertTrue(familyNameMatch1.getRelevancyScore() < 1);
}
Aggregations