use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class SolrDaoTest method queryFieldWithBoost.
@Test
public void queryFieldWithBoost() throws Exception {
OrcidSolrDocument firstOrcidDoc = buildFirstOrcid();
firstOrcidDoc.setOrcid(firstOrcid);
firstOrcidDoc.setFamilyName("James");
OrcidSolrDocument secondOrcidDoc = buildSupplementaryOrcid();
secondOrcidDoc.setOrcid(secondOrcid);
secondOrcidDoc.setGivenNames("James");
solrDao.persist(firstOrcidDoc);
solrDao.persist(secondOrcidDoc);
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() == 2);
assertTrue(solrResults.get(0).getOrcid().equals(secondOrcid));
assertTrue(solrResults.get(1).getOrcid().equals(firstOrcid));
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class SolrDaoTest method queryFieldWithKeyword.
@Test
public void queryFieldWithKeyword() throws Exception {
buildAndPersistFirstOrcid();
OrcidSolrDocument secondDoc = buildSupplementaryOrcid();
String subjectKeyword1 = "Advanced Muppetry";
String subjectKeyword2 = "Basic Muppetry";
secondDoc.setOrcid(secondOrcid);
secondDoc.setKeywords(Arrays.asList(subjectKeyword1, subjectKeyword2));
persistOrcid(secondDoc);
String familyNameKeywordsQueryString = "given-names:given AND keyword:basic";
List<OrcidSolrResult> solrResults = solrDao.findByDocumentCriteria(familyNameKeywordsQueryString, null, null).getResults();
assertTrue(solrResults.size() == 1);
OrcidSolrResult result = solrResults.get(0);
assertEquals(secondOrcid, result.getOrcid());
familyNameKeywordsQueryString = "given-names:given AND keyword:advanced";
solrResults = solrDao.findByDocumentCriteria(familyNameKeywordsQueryString, null, null).getResults();
assertTrue(solrResults.size() == 1);
result = solrResults.get(0);
assertEquals(secondOrcid, result.getOrcid());
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class SolrDaoTest method queryFieldWeyword.
@Test
public void queryFieldWeyword() throws Exception {
buildAndPersistFirstOrcid();
OrcidSolrDocument secondDoc = buildSupplementaryOrcid();
String subjectKeyword1 = "Advanced Muppetry";
String subjectKeyword2 = "Basic Muppetry";
secondDoc.setOrcid(secondOrcid);
secondDoc.setKeywords(Arrays.asList(subjectKeyword1, subjectKeyword2));
persistOrcid(secondDoc);
String familyNameKeywordsQueryString = "given-names:given AND keyword:basic";
List<OrcidSolrResult> solrResults = solrDao.findByDocumentCriteria(familyNameKeywordsQueryString, null, null).getResults();
assertTrue(solrResults.size() == 1);
OrcidSolrResult result = solrResults.get(0);
assertEquals(secondOrcid, result.getOrcid());
familyNameKeywordsQueryString = "given-names:given AND keyword:advanced";
solrResults = solrDao.findByDocumentCriteria(familyNameKeywordsQueryString, null, null).getResults();
assertTrue(solrResults.size() == 1);
result = solrResults.get(0);
assertEquals(secondOrcid, result.getOrcid());
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class SolrDaoTest method queryStringSearchPatent.
@Test
public void queryStringSearchPatent() throws Exception {
OrcidSolrDocument firstOrcid = buildAndPersistFirstOrcid();
String patentQueryString = "patent-numbers:Elec-hammer01X%3A";
OrcidSolrResults orcidSolrResults = solrDao.findByDocumentCriteria(patentQueryString, null, null);
List<OrcidSolrResult> solrResultsList = orcidSolrResults.getResults();
assertTrue(solrResultsList.size() == 1);
assertEquals(firstOrcid.getOrcid(), solrResultsList.get(0).getOrcid());
}
use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.
the class OrcidSearchManagerImpl method buildSearchResultsFromPublicProfile.
private List<OrcidSearchResult> buildSearchResultsFromPublicProfile(List<OrcidSolrResult> solrResults) {
List<OrcidSearchResult> orcidSearchResults = new ArrayList<OrcidSearchResult>();
for (OrcidSolrResult solrResult : solrResults) {
OrcidMessage orcidMessage = null;
String orcid = solrResult.getOrcid();
try {
orcidSecurityManager.checkProfile(orcid);
} catch (DeactivatedException | LockedException | OrcidDeprecatedException x) {
OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
RelevancyScore relevancyScore = new RelevancyScore();
relevancyScore.setValue(solrResult.getRelevancyScore());
orcidSearchResult.setRelevancyScore(relevancyScore);
OrcidProfile orcidProfile = new OrcidProfile();
orcidProfile.setOrcidIdentifier(new OrcidIdentifier(jpaJaxbAdapter.getOrcidIdBase(orcid)));
OrcidHistory history = new OrcidHistory();
Date recordLastModified = profileDaoReadOnly.retrieveLastModifiedDate(orcid);
history.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(recordLastModified)));
orcidProfile.setOrcidHistory(history);
orcidSearchResult.setOrcidProfile(orcidProfile);
orcidSearchResults.add(orcidSearchResult);
continue;
}
if (cachingSource.equals(SOLR)) {
try (Reader reader = solrDao.findByOrcidAsReader(orcid)) {
if (reader != null) {
BufferedReader br = new BufferedReader(reader);
orcidMessage = OrcidMessage.unmarshall(br);
}
} catch (IOException e) {
throw new OrcidSearchException("Error closing record stream from solr search results for orcid: " + orcid, e);
}
}
OrcidProfile orcidProfile = null;
if (orcidMessage == null) {
// Fall back to DB
orcidProfile = orcidProfileCacheManager.retrievePublicBio(orcid);
} else {
orcidProfile = orcidMessage.getOrcidProfile();
}
if (orcidProfile != null) {
OrcidSearchResult orcidSearchResult = new OrcidSearchResult();
RelevancyScore relevancyScore = new RelevancyScore();
relevancyScore.setValue(solrResult.getRelevancyScore());
orcidSearchResult.setRelevancyScore(relevancyScore);
OrcidWorks orcidWorksTitlesOnly = new OrcidWorks();
OrcidWorks fullOrcidWorks = orcidProfile.retrieveOrcidWorks();
if (fullOrcidWorks != null && !fullOrcidWorks.getOrcidWork().isEmpty()) {
for (OrcidWork fullOrcidWork : fullOrcidWorks.getOrcidWork()) {
OrcidWork orcidWorkSubset = new OrcidWork();
orcidWorkSubset.setVisibility(fullOrcidWork.getVisibility());
orcidWorkSubset.setWorkTitle(fullOrcidWork.getWorkTitle());
orcidWorkSubset.setWorkExternalIdentifiers(fullOrcidWork.getWorkExternalIdentifiers());
orcidWorksTitlesOnly.getOrcidWork().add(orcidWorkSubset);
}
}
FundingList reducedFundings = new FundingList();
FundingList fullOrcidFundings = orcidProfile.retrieveFundings();
if (fullOrcidFundings != null && !fullOrcidFundings.getFundings().isEmpty()) {
for (Funding fullOrcidFunding : fullOrcidFundings.getFundings()) {
Funding reducedFunding = new Funding();
reducedFunding.setVisibility(fullOrcidFunding.getVisibility());
reducedFunding.setDescription(fullOrcidFunding.getDescription());
reducedFunding.setTitle(fullOrcidFunding.getTitle());
reducedFundings.getFundings().add(reducedFunding);
}
}
orcidProfile.setOrcidWorks(orcidWorksTitlesOnly);
orcidProfile.setFundings(reducedFundings);
orcidSearchResult.setOrcidProfile(orcidProfile);
orcidSearchResults.add(orcidSearchResult);
}
}
return orcidSearchResults;
}
Aggregations