Search in sources :

Example 6 with OrcidSolrResult

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;
}
Also used : OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) SolrDocument(org.apache.solr.common.SolrDocument) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults)

Example 7 with OrcidSolrResult

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;
}
Also used : OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) SolrDocument(org.apache.solr.common.SolrDocument) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 8 with 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;
}
Also used : OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) ArrayList(java.util.ArrayList) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults)

Example 9 with OrcidSolrResult

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;
}
Also used : OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult)

Example 10 with OrcidSolrResult

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);
}
Also used : OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) Test(org.junit.Test)

Aggregations

OrcidSolrResult (org.orcid.utils.solr.entities.OrcidSolrResult)19 OrcidSolrDocument (org.orcid.utils.solr.entities.OrcidSolrDocument)11 Test (org.junit.Test)9 OrcidSolrResults (org.orcid.utils.solr.entities.OrcidSolrResults)8 ArrayList (java.util.ArrayList)5 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)4 OrcidSearchResult (org.orcid.jaxb.model.message.OrcidSearchResult)4 OrcidSearchResults (org.orcid.jaxb.model.message.OrcidSearchResults)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 SolrDocument (org.apache.solr.common.SolrDocument)2 NonTransientDataAccessResourceException (org.springframework.dao.NonTransientDataAccessResourceException)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 List (java.util.List)1 Map (java.util.Map)1 OrcidSearchException (org.orcid.core.exception.OrcidSearchException)1 Funding (org.orcid.jaxb.model.message.Funding)1