Search in sources :

Example 11 with OrcidSolrResult

use of org.orcid.utils.solr.entities.OrcidSolrResult in project ORCID-Source by ORCID.

the class SolrDaoTest method queryStringSearchFamilyNameGivenNameTenRows.

@Test
public void queryStringSearchFamilyNameGivenNameTenRows() throws Exception {
    int numRecordsToCreate = 10;
    List<String> orcidsToGetStored = new ArrayList<String>();
    for (int i = 0; i < numRecordsToCreate; i++) {
        OrcidSolrDocument orcidSolrDocument = buildSupplementaryOrcid();
        orcidSolrDocument.setGivenNames(RandomStringUtils.randomAscii(20));
        // format of orcid irrelevant to solr - just need to make them
        // different
        orcidSolrDocument.setOrcid(RandomStringUtils.randomAscii(20));
        orcidsToGetStored.add(orcidSolrDocument.getOrcid());
        persistOrcid(orcidSolrDocument);
    }
    String familyNameOnlyQuery = "family-name:Family Name";
    List<OrcidSolrResult> solrResults = solrDao.findByDocumentCriteria(familyNameOnlyQuery, null, null).getResults();
    assertTrue(solrResults.size() == 10);
    familyNameOnlyQuery = "{!start=0 rows=5} family-name:Family Name";
    solrResults = solrDao.findByDocumentCriteria(familyNameOnlyQuery, null, null).getResults();
    assertTrue(solrResults.size() == 5);
}
Also used : OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with OrcidSolrResult

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

Example 13 with OrcidSolrResult

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

Example 14 with OrcidSolrResult

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

Example 15 with OrcidSolrResult

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