Example usage for org.apache.solr.common SolrDocumentList getNumFound

List of usage examples for org.apache.solr.common SolrDocumentList getNumFound

Introduction

In this page you can find the example usage for org.apache.solr.common SolrDocumentList getNumFound.

Prototype

public long getNumFound() 

Source Link

Usage

From source file:fi.vm.sade.organisaatio.service.search.OrganisaatioSearchService.java

License:EUPL

public List<String> findParentOids(String organisationOid) {
    final SolrQuery q = new SolrQuery(String.format(SolrOrgFields.OID + ":%s", organisationOid));
    q.setFields(SolrOrgFields.PATH);//w  w w. j av  a 2 s .com
    final List<String> oids = Lists.newArrayList();

    SolrDocumentList docList;
    try {
        docList = solr.query(q).getResults();
        if (docList.getNumFound() == 1) {
            SolrDocument doc = docList.get(0);
            for (Object field : doc.getFieldValues(SolrOrgFields.PATH)) {
                if (!rootOrganisaatioOid.equals(field)) {
                    oids.add((String) field);
                }
            }
        }

    } catch (SolrServerException e) {
        throw new RuntimeException(e);
    }

    return oids;
}

From source file:fr.cnes.sitools.metacatalogue.CswMetadataIndexerTestCase.java

License:Open Source License

private void assertMetadataInserted() throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");

    QueryResponse rsp = server.query(query);
    assertNotNull(rsp);/*from   w w  w.j ava 2 s  .c  o  m*/
    SolrDocumentList listDoc = rsp.getResults();
    assertNotNull(listDoc);
    assertEquals(nbFieldsExpected, listDoc.getNumFound());
}

From source file:fr.cnes.sitools.metacatalogue.thesaurus.ThesaurusTestUtils.java

License:Open Source License

private void assertNbRecords(SolrServer server, int nbRecords) throws SolrServerException {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");
    QueryResponse rsp = server.query(solrQuery);
    SolrDocumentList listDoc = rsp.getResults();

    assertEquals(nbRecords, listDoc.getNumFound());

}

From source file:fr.mcc.ginco.services.IndexerServiceImpl.java

License:CeCILL license

private SearchResultList getSearchResultList(SolrDocumentList list) {
    SearchResultList results = new SearchResultList();
    results.setNumFound(list.getNumFound());
    for (int i = 0; i < list.size(); ++i) {
        results.add(getSearchResult(list.get(i)));
    }//from w  ww .j  a v  a 2 s.com
    return results;
}

From source file:fr.mcc.ginco.solr.SearcherServiceUtil.java

License:CeCILL license

public SearchResultList getSearchResultList(SolrDocumentList list) {
    SearchResultList results = new SearchResultList();
    results.setNumFound(list.getNumFound());
    for (int i = 0; i < list.size(); ++i) {
        results.add(getSearchResult(list.get(i)));
    }/* ww w .j a  v  a  2 s  .  c  o m*/
    return results;
}

From source file:gc.solr.task.Gptdb2SolrTask.java

License:Apache License

private void walkSolrDocs() throws SolrServerException, IOException {
    if (!checkForDeletes)
        return;// w ww. ja v  a  2 s.c om
    if ((okIds == null) || (okIds.size() == 0))
        return;

    TaskContext context = this.getContext();
    TaskStats stats = context.getStats();
    String tn = context.getTaskName() + ".walkSolrDocs";
    stats.setString(tn, "...");

    String fl = FieldConstants.Id;
    String q = FieldConstants.Id_Table + ":" + FieldConstants.Val_Id_Table_DocIndex;
    q += " AND " + FieldConstants.Sync_Type + ":" + this.syncType;
    q += " AND " + FieldConstants.Sync_Foreign_InstanceId + ":" + this.foreignInstanceId;
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", q);
    params.set("fl", fl);
    stats.setString(tn + ".q", q);

    boolean bContinue = true;
    long nDeepTotal = 0;
    long nFetched = 0;
    long nHits = 0;
    int nDocs = 0;
    long nStart = 0;
    int nRows = 1000;
    long nNextStart = 0;
    while (bContinue) {
        bContinue = false;
        params.set("start", "" + nStart);
        params.set("rows", "" + nRows);
        QueryResponse response = queryServer.query(params);
        SolrDocumentList docs = response.getResults();
        if (docs != null) {
            nHits = docs.getNumFound();
            nDocs = docs.size();
            nNextStart = nStart + nDocs;
            if ((nDocs > 0) && (nNextStart < nHits)) {
                bContinue = true;
            }
            for (int i = 0; i < nDocs; i++) {
                SolrDocument doc = docs.get(i);
                String id = (String) doc.getFieldValue(FieldConstants.Id);
                nFetched++;
                stats.incrementCount(tn + ".fetched");
                if (okIds.get(id) != null) {
                    stats.incrementCount(tn + ".idOk");
                } else {
                    stats.incrementCount(tn + ".idRequiresDelete");
                    if ((delIds != null) && (delIds.size() <= this.maxIdsInMap)) {
                        delIds.add(id);
                    } else if (delIds != null) {
                        delIds = null;
                        bContinue = false;
                        break;
                    }
                }
                if ((nDeepTotal > 0) && (nFetched >= nDeepTotal)) {
                    bContinue = false;
                    break;
                }
            }
            nStart = nNextStart;
        }
    }

    if ((delIds != null) && (delIds.size() > 0)) {
        stats.incrementCount(context.getTaskName() + ".solr.sentForDelete", delIds.size());
        this.docPublisher.getUpdateServer().deleteById(delIds);
    }

}

From source file:gr.aueb.service.EmailService.java

public static List<Email> getEmails(List<String> keywords) {
    String query = getEmailServiceQuery(keywords);
    SolrQuery solrQuery;/*w  w  w.ja v a2s  .  c om*/
    solrQuery = new SolrQuery();
    if (query.startsWith(" AND")) {
        query = query.substring(4);
    }
    if (query.startsWith("AND")) {
        query = query.substring(3);
    }
    solrQuery.setQuery(query);
    if (!query.equals("")) {
        solrQuery.setHighlight(true).setHighlightSnippets(1).setHighlightSimplePost("</strong>")
                .setHighlightSimplePre("<strong>"); //set other params as needed
        solrQuery.setParam("hl.fl", "content_t");
        solrQuery.setParam("hl.requireFieldMatch", "true");

    }

    solrQuery.setRows(15);
    String urlString = "http://195.251.252.8:8983/solr/mail";
    //SolrClient server = new HttpSolrClient.Builder(urlString).build();
    SolrClient server = new HttpSolrClient(urlString);
    QueryResponse response = null;
    try {
        response = server.query(solrQuery);

    } catch (Exception e) {
        System.out.println(e);
    }
    SolrDocumentList rs = response.getResults();
    long numFound = rs.getNumFound();
    int numResultsDisplay = (int) numFound;
    ArrayList<Email> items = new ArrayList<Email>();

    ListIterator<SolrDocument> iter = rs.listIterator();

    while (iter.hasNext()) {
        SolrDocument doc = iter.next();
        String id = doc.get("messageId").toString();
        String from = doc.get("from").toString();
        String sentDate = doc.get("sentDate").toString();
        String subject = doc.get("subject").toString();
        String content = doc.get("content").toString();

        items.add(new Email(id, from, sentDate, subject, content));
    }
    return items;
}

From source file:info.papyri.dispatch.atom.AtomFeedServlet.java

License:Creative Commons License

/**
 * Deals with feed pagination./*from   www.  j av  a2 s  .c  o m*/
 * 
 * @param feed
 * @param dateParams
 * @param page
 * @param results 
 */

void paginateFeed(Feed feed, EnumMap<TimeParam, String> dateParams, int page, SolrDocumentList results) {

    long numResults = results.getNumFound();
    if (numResults <= entriesPerPage)
        return;

    Link startLink = abdera.getFactory().newLink();
    startLink.setRel("first");
    startLink.setHref(SELF);
    feed.addLink(startLink);

    String pageQS = SELF + buildDateQueryString(dateParams) + PAGE + "=";
    long lastPage = numResults / entriesPerPage + (numResults % entriesPerPage == 0 ? 0 : 1);

    Link lastLink = abdera.getFactory().newLink();
    lastLink.setRel("last");
    lastLink.setHref(pageQS + String.valueOf(lastPage));
    feed.addLink(lastLink);

    if (page > 1) {

        Link prevLink = abdera.getFactory().newLink();
        prevLink.setRel("previous");
        prevLink.setHref(pageQS + String.valueOf(page - 1));
        feed.addLink(prevLink);

    }

    if (page < lastPage) {

        Link nextLink = abdera.getFactory().newLink();
        nextLink.setRel("next");
        nextLink.setHref(pageQS + String.valueOf(page + 1));
        feed.addLink(nextLink);

    }

}

From source file:io.logspace.hq.core.solr.report.SolrReportService.java

License:Open Source License

@Override
public Reports getReports(int start, int count, String sort) {
    this.logger.debug("Retrieving {} reports from {}, sorted by '{}'.", count, start, sort);

    SolrQuery solrQuery = new SolrQuery("*:*");

    solrQuery.addFilterQuery(FILTER_REPORT);
    solrQuery.addFilterQuery(FILTER_UNDELETED);
    solrQuery.addFilterQuery(FILTER_TIP_OF_BRANCH);

    SolrQueryHelper.addSort(solrQuery, sort, this.getFieldDefinitions());
    SolrQueryHelper.setRange(solrQuery, start, count);

    try {/*  w  w w. ja  v a2  s . c o m*/
        List<Report> reports = new ArrayList<>();

        QueryResponse queryResponse = this.solrClient.query(solrQuery);
        SolrDocumentList results = queryResponse.getResults();
        for (SolrDocument eachSolrDocument : results) {
            reports.add(createReport(eachSolrDocument));
        }

        return Reports.create(reports, start, Math.toIntExact(results.getNumFound()));
    } catch (SolrServerException | IOException e) {
        throw new DataRetrievalException("Could not retrieve reports.", e);
    }
}

From source file:jp.aegif.nemaki.cmis.aspect.query.solr.SolrPredicateWalker.java

License:Open Source License

/**
 * Get all subfolder ids by connecting to Solr recursively
 *
 * @param folderId/*from w w  w . j a va 2s .  c om*/
 * @param solrServer
 * @return
 */
private List<String> getDescendantFolderId(String folderId, SolrServer solrServer) {
    List<String> list = new ArrayList<String>();

    list.add(folderId); // Add oneself to the list in advance

    SolrQuery query = new SolrQuery();

    query.setQuery(solrUtil.getPropertyNameInSolr(repositoryId, PropertyIds.PARENT_ID) + ":" + folderId
            + " AND " + solrUtil.getPropertyNameInSolr(repositoryId, PropertyIds.BASE_TYPE_ID)
            + ":cmis\\:folder"); // only "folder" nodes

    // Connect to SolrServer and add subfolder ids to the list
    try {
        QueryResponse resp = solrServer.query(query);
        SolrDocumentList children = resp.getResults();
        // END NODE case: Do nothing but return oneself
        if (children.getNumFound() == 0) {
            return list;
            // Other than END NODE case: collect descendants values
            // recursively
        } else {
            Iterator<SolrDocument> iterator = resp.getResults().iterator();
            while (iterator.hasNext()) {
                SolrDocument child = iterator.next();
                String childId = (String) child.getFieldValue("id");
                // Recursive call to this method
                List<String> l = getDescendantFolderId(childId, solrServer);
                list.addAll(l);
            }
            return list;
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
        return null;
    }
}