Search in sources :

Example 1 with SolrDocument

use of org.apache.solr.common.SolrDocument in project Xponents by OpenSextant.

the class SolrProxy method searchGazetteer.

/**
     * Search an OpenSextant solr gazetteer.
     *
     * @param index solr server handle
     * @param qparams search parameters
     * @return list of places
     * @throws SolrServerException on err
     */
public static List<Place> searchGazetteer(SolrServer index, SolrParams qparams) throws SolrServerException {
    QueryResponse response = index.query(qparams, SolrRequest.METHOD.GET);
    List<Place> places = new ArrayList<>();
    SolrDocumentList docList = response.getResults();
    for (SolrDocument solrDoc : docList) {
        places.add(SolrProxy.createPlace(solrDoc));
    }
    return places;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Place(org.opensextant.data.Place)

Example 2 with SolrDocument

use of org.apache.solr.common.SolrDocument in project Xponents by OpenSextant.

the class GazetteerMatcher method searchAdvanced.

/**
     * This is a variation on SolrGazetteer.search(), just this creates ScoredPlace which is
     * immediately usable with scoring and ranking matches. The score for a ScoredPlace is
     * created when added to PlaceCandidate: a default score is created for the place.
     * 
     * <pre>
     *    Usage:
     *    pc = PlaceCandidate();
     *    list = gaz.searchAdvanced("name:Boston", true)  // solr fielded query used as-is.
     *    for ScoredPlace p: list:
     *        pc.addPlace( p )
     * </pre>
     * 
     * @param place
     *            the place string or text; or a Solr query
     * @param as_solr
     *            the as_solr
     * @param maxLen
     *            max length of gazetteer place names.
     * @return places List of scoreable place entries
     * @throws SolrServerException
     *             the solr server exception
     */
public List<ScoredPlace> searchAdvanced(String place, boolean as_solr, int maxLen) throws SolrServerException {
    if (as_solr) {
        params.set("q", place);
    } else {
        // Bare keyword query needs to be quoted as "word word word"
        params.set("q", "\"" + place + "\"");
    }
    QueryResponse response = solr.getInternalSolrServer().query(params, SolrRequest.METHOD.GET);
    List<ScoredPlace> places = new ArrayList<>();
    for (SolrDocument solrDoc : response.getResults()) {
        /*
             * Length Filter.  Alternative: store name as string in solr, vice full text field 
             */
        if (maxLen > 0) {
            String nm = SolrProxy.getString(solrDoc, "name");
            if (nm.length() > maxLen) {
                continue;
            }
        }
        places.add(createPlace(solrDoc));
    }
    return places;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ArrayList(java.util.ArrayList)

Example 3 with SolrDocument

use of org.apache.solr.common.SolrDocument 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 4 with SolrDocument

use of org.apache.solr.common.SolrDocument in project ORCID-Source by ORCID.

the class SolrDaoImpl method retrieveLastModified.

@Override
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 5 with SolrDocument

use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.

the class TestContentStreamDataSource method testSimple.

@Test
public void testSimple() throws Exception {
    DirectXmlRequest req = new DirectXmlRequest("/dataimport", xml);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("command", "full-import");
    params.set("clean", "false");
    req.setParams(params);
    try (HttpSolrClient solrClient = getHttpSolrClient(buildUrl(jetty.getLocalPort(), "/solr/collection1"))) {
        solrClient.request(req);
        ModifiableSolrParams qparams = new ModifiableSolrParams();
        qparams.add("q", "*:*");
        QueryResponse qres = solrClient.query(qparams);
        SolrDocumentList results = qres.getResults();
        assertEquals(2, results.getNumFound());
        SolrDocument doc = results.get(0);
        assertEquals("1", doc.getFieldValue("id"));
        assertEquals("Hello C1", ((List) doc.getFieldValue("desc")).get(0));
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) DirectXmlRequest(org.apache.solr.client.solrj.request.DirectXmlRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Aggregations

SolrDocument (org.apache.solr.common.SolrDocument)353 SolrDocumentList (org.apache.solr.common.SolrDocumentList)159 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)134 SolrQuery (org.apache.solr.client.solrj.SolrQuery)86 ArrayList (java.util.ArrayList)84 SolrServerException (org.apache.solr.client.solrj.SolrServerException)66 IOException (java.io.IOException)62 Test (org.junit.Test)62 SolrInputDocument (org.apache.solr.common.SolrInputDocument)46 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)44 SolrParams (org.apache.solr.common.params.SolrParams)44 HashMap (java.util.HashMap)39 NamedList (org.apache.solr.common.util.NamedList)30 Map (java.util.Map)29 List (java.util.List)26 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)26 SolrClient (org.apache.solr.client.solrj.SolrClient)20 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)17 Date (java.util.Date)16 HashSet (java.util.HashSet)13