Search in sources :

Example 6 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery 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);
    }
}
Also used : 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) Date(java.util.Date)

Example 7 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project ORCID-Source by ORCID.

the class OrgDisambiguatedSolrDaoImpl method findById.

@Override
public OrgDisambiguatedSolrDocument findById(Long id) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORG_DISAMBIGUATED_ID + ":" + id).setFields("*");
    try {
        QueryResponse queryResponse = solrServerReadOnly.query(query);
        if (!queryResponse.getResults().isEmpty()) {
            OrgDisambiguatedSolrDocument document = queryResponse.getBeans(OrgDisambiguatedSolrDocument.class).get(0);
            return document;
        }
    } catch (SolrServerException se) {
        String errorMessage = MessageFormat.format("Error when attempting to retrieve org {0}", new Object[] { id });
        throw new NonTransientDataAccessResourceException(errorMessage, se);
    }
    return null;
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) OrgDisambiguatedSolrDocument(org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 8 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project ORCID-Source by ORCID.

the class AppContextSolrTest method testServerRunning.

@Test
@Ignore
public void testServerRunning() throws Exception {
    SolrQuery solrQuery = new SolrQuery().setQuery("carberry");
    QueryResponse response = solrServer.query(solrQuery);
    assertNotNull(response);
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project ORCID-Source by ORCID.

the class FundingSubtypeSolrDaoImpl method getFundingTypes.

@Override
public List<OrgDefinedFundingTypeSolrDocument> getFundingTypes(String searchTerm, int firstResult, int maxResult) {
    SolrQuery query = new SolrQuery();
    query.setQuery("{!edismax qf='org-defined-funding-type^50.0 text^1.0' pf='org-defined-funding-type^50.0' mm=1 sort='score desc'}" + searchTerm + "*").setFields("*");
    try {
        QueryResponse queryResponse = solrServerReadOnly.query(query);
        return queryResponse.getBeans(OrgDefinedFundingTypeSolrDocument.class);
    } catch (SolrServerException se) {
        String errorMessage = MessageFormat.format("Error when attempting to search for orgs, with search term {0}", new Object[] { searchTerm });
        throw new NonTransientDataAccessResourceException(errorMessage, se);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 10 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project ORCID-Source by ORCID.

the class SolrDaoImpl method findByDocumentCriteria.

@Override
public OrcidSolrResults findByDocumentCriteria(Map<String, List<String>> queryMap) {
    OrcidSolrResults orcidSolrResults = new OrcidSolrResults();
    List<OrcidSolrResult> orcidSolrResultsList = new ArrayList<>();
    orcidSolrResults.setResults(orcidSolrResultsList);
    SolrQuery solrQuery = new SolrQuery();
    for (Map.Entry<String, List<String>> entry : queryMap.entrySet()) {
        String queryKey = entry.getKey();
        List<String> queryVals = entry.getValue();
        solrQuery.add(queryKey, queryVals.get(0));
    }
    solrQuery.setFields(SCORE, ORCID);
    return querySolr(solrQuery);
}
Also used : OrcidSolrResult(org.orcid.utils.solr.entities.OrcidSolrResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) SolrQuery(org.apache.solr.client.solrj.SolrQuery) OrcidSolrResults(org.orcid.utils.solr.entities.OrcidSolrResults)

Aggregations

SolrQuery (org.apache.solr.client.solrj.SolrQuery)316 Test (org.junit.Test)174 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)123 SolrInputDocument (org.apache.solr.common.SolrInputDocument)52 SolrServerException (org.apache.solr.client.solrj.SolrServerException)50 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)45 SolrDocument (org.apache.solr.common.SolrDocument)45 ArrayList (java.util.ArrayList)44 IOException (java.io.IOException)33 SolrDocumentList (org.apache.solr.common.SolrDocumentList)33 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)32 SolrClient (org.apache.solr.client.solrj.SolrClient)27 LinearModel (org.apache.solr.ltr.model.LinearModel)24 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)23 Replica (org.apache.solr.common.cloud.Replica)23 Slice (org.apache.solr.common.cloud.Slice)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)21 Map (java.util.Map)20 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 SolrException (org.apache.solr.common.SolrException)18