Example usage for org.apache.solr.client.solrj SolrQuery setFacetLimit

List of usage examples for org.apache.solr.client.solrj SolrQuery setFacetLimit

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrQuery setFacetLimit.

Prototype

public SolrQuery setFacetLimit(int lim) 

Source Link

Document

set the facet limit

Usage

From source file:uk.ac.ebi.atlas.solr.query.builders.FacetedPropertyValueQueryBuilder.java

License:Apache License

private SolrQuery buildQueryObject(String queryString) {
    SolrQuery solrQuery = new SolrQuery(queryString);

    solrQuery.addFacetField(PROPERTY_LOWER_FIELD);
    solrQuery.setRows(0);//w  w  w.  j  a v a2  s . c  om
    solrQuery.setFacet(true);
    solrQuery.setFacetLimit(DEFAULT_LIMIT);
    solrQuery.setFacetMinCount(1);

    return solrQuery;
}

From source file:uk.ac.ebi.atlas.solr.query.SpeciesLookupService.java

License:Apache License

public Result fetchSpeciesForGeneSet(String term) {
    // eg: property_value_lower:"IPR027417"
    String queryText = PROPERTY_LOWER_FIELD + ":" + encloseInQuotes(term)
            + " AND property_name:(pathwayid OR go OR po OR interpro OR REACT_303889)"; // Needed to exclude Entrez numerical ids, identical to Plant Reactome ids (pathwayid)
    LOGGER.debug("fetch species for geneset " + queryText);

    SolrQuery query = new SolrQuery(queryText);

    query.addFacetField(SPECIES_FIELD);/* ww  w  .  java  2 s.  c  o  m*/
    query.setRows(0);
    query.setFacet(true);

    // just get first 2 species for performance reasons, we only need to know if multi-species exist, not what they are
    query.setFacetLimit(2);
    query.setFacetMinCount(1);

    QueryResponse solrResponse = solrServer.query(query);
    ImmutableSet<String> species = SolrUtil.extractFirstFacetValues(solrResponse);

    return new Result(species);
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.IntactSolrSearcher.java

License:Apache License

public Map<String, Integer> countAllInteractors(SolrQuery originalQuery, String[] interactorTypeMis)
        throws IntactSolrException {
    boolean endOfFacetResults = false;

    int firstResults = 0;

    Map<String, Integer> results = new HashMap<String, Integer>();

    while (!endOfFacetResults) {
        int chunkResults = 0;

        SolrQuery query = originalQuery.getCopy();
        query.setRows(0);//from  w w  w  .j av  a 2 s  .  co m

        // we allow faceting
        query.setFacet(true);

        // we want all the facet fields with min count = 1. The facet fields with count = 0 are not interesting
        query.setFacetMinCount(1);

        // important optimization. We don't want to return all the fields, only a certain number for pagination
        query.set(FacetParams.FACET_OFFSET, firstResults);
        query.setFacetLimit(CHUNK_FACET_THRESHOLD);

        // we sort the results : the biggest count first
        query.setFacetSort(FacetParams.FACET_SORT_COUNT);

        for (String mi : interactorTypeMis) {
            final String fieldName = createFieldName(mi);

            query.addFacetField(fieldName);
        }

        QueryResponse queryResponse = executeQuery(query);

        List<FacetField> facetFields = queryResponse.getFacetFields();
        if (facetFields == null || facetFields.isEmpty()) {
            endOfFacetResults = true;
        } else {
            for (FacetField facetField : facetFields) {
                if (facetField.getValueCount() > 0) {
                    chunkResults += facetField.getValueCount();

                    if (results.containsKey(facetField.getName())) {
                        int current = results.get(facetField.getName());
                        results.put(facetField.getName(), current + facetField.getValueCount());
                    } else {
                        results.put(facetField.getName(), facetField.getValueCount());
                    }
                } else if (!results.containsKey(facetField.getName())) {
                    results.put(facetField.getName(), 0);
                }
            }

            if (chunkResults < CHUNK_FACET_THRESHOLD) {
                endOfFacetResults = true;
            }
        }

        firstResults += CHUNK_FACET_THRESHOLD;
    }

    return results;
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.ontology.OntologySearcher.java

License:Apache License

public Set<String> getOntologyNames() throws SolrServerException {
    if (ontologyNames == null) {
        SolrQuery query = new SolrQuery("*:*");
        query.setStart(0);/* ww w . j a v  a2s  . co  m*/
        query.setRows(0);

        // prepare faceting
        query.setFacet(true);
        query.setParam(FacetParams.FACET_FIELD, "ontology");
        query.setFacetLimit(10);
        query.setFacetMinCount(1);
        query.set(FacetParams.FACET_OFFSET, 0);

        // order by unique id
        query.addSortField(OntologyFieldNames.ID, SolrQuery.ORDER.asc);

        QueryResponse response = search(query, null);
        FacetField facetField = response.getFacetField("ontology");

        if (facetField.getValues() == null) {
            return Collections.EMPTY_SET;
        }

        ontologyNames = new HashSet<String>(facetField.getValues().size());

        for (FacetField.Count c : facetField.getValues()) {
            ontologyNames.add(c.getName());
        }
    }

    return ontologyNames;
}

From source file:uk.ac.ebi.phenotype.service.ObservationService.java

License:Apache License

public Map<String, Set<String>> getColoniesByPhenotypingCenter(ArrayList<String> resourceName,
        ZygosityType zygosity) throws SolrServerException, InterruptedException {

    Map<String, Set<String>> res = new HashMap<>();
    SolrQuery q = new SolrQuery();
    String pivotFacet = ObservationDTO.PHENOTYPING_CENTER + "," + ObservationDTO.COLONY_ID;
    NamedList<List<PivotField>> response;

    if (resourceName != null) {
        q.setQuery(ObservationDTO.DATASOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":"));
    } else {/*from   w  w w.  java2s.com*/
        q.setQuery("*:*");
    }

    if (zygosity != null) {
        q.addFilterQuery(ObservationDTO.ZYGOSITY + ":" + zygosity.name());
    }

    q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental");
    q.addFacetPivotField(pivotFacet);
    q.setFacet(true);
    q.setFacetLimit(-1);
    q.setFacetMinCount(1);
    q.setRows(0);

    try {
        response = solr.query(q).getFacetPivot();
        for (PivotField genePivot : response.get(pivotFacet)) {
            String center = genePivot.getValue().toString();
            HashSet<String> colonies = new HashSet<>();
            for (PivotField f : genePivot.getPivot()) {
                colonies.add(f.getValue().toString());
            }
            res.put(center, colonies);
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return res;
}

From source file:uk.ac.ebi.phenotype.service.ObservationService.java

License:Apache License

public Set<String> getAllGeneIdsByResource(List<String> resourceName, boolean experimentalOnly) {

    SolrQuery q = new SolrQuery();
    q.setFacet(true);//from   w ww. j a va  2s  . c  o  m
    q.setFacetMinCount(1);
    q.setFacetLimit(-1);
    q.setRows(0);
    q.addFacetField(ObservationDTO.GENE_ACCESSION_ID);
    if (resourceName != null) {
        q.setQuery(ObservationDTO.DATASOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":"));
    } else {
        q.setQuery("*:*");
    }

    if (experimentalOnly) {
        q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental");
    }

    LOG.info("Solr URL getAllGeneIdsByResource " + solr.getBaseURL() + "/select?" + q);
    try {
        return getFacets(solr.query(q)).get(ObservationDTO.GENE_ACCESSION_ID).keySet();
    } catch (SolrServerException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:uk.ac.ebi.phenotype.service.ObservationService.java

License:Apache License

public Set<String> getAllColonyIdsByResource(List<String> resourceName, boolean experimentalOnly) {

    SolrQuery q = new SolrQuery();
    q.setFacet(true);/*ww  w  .  j  a  v a  2 s .c  o m*/
    q.setFacetMinCount(1);
    q.setFacetLimit(-1);
    q.setRows(0);
    q.addFacetField(ObservationDTO.COLONY_ID);

    if (resourceName != null) {
        q.setQuery(ObservationDTO.DATASOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":"));
    } else {
        q.setQuery("*:*");
    }

    if (experimentalOnly) {
        q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental");
    }

    LOG.info("Solr URL getAllColonyIdsByResource " + solr.getBaseURL() + "/select?" + q);
    try {
        return getFacets(solr.query(q)).get(ObservationDTO.COLONY_ID).keySet();
    } catch (SolrServerException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:uk.ac.ebi.phenotype.service.StatisticalResultService.java

License:Apache License

/**
 * @return Map <String, Long> : <top_level_mp_name, number_of_annotations>
 * @author tudose//from w  w  w.  j  a  va 2  s . c o  m
 */
public TreeMap<String, Long> getDistributionOfAnnotationsByMPTopLevel(ArrayList<String> resourceName,
        Float pValueThreshold) {

    SolrQuery query = new SolrQuery();

    if (resourceName != null) {
        query.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + StatisticalResultDTO.RESOURCE_NAME + ":"));
    } else {
        query.setQuery("*:*");
    }

    if (pValueThreshold != null) {
        query.setFilterQueries(StatisticalResultDTO.P_VALUE + ":[0 TO " + pValueThreshold + "]");
    }

    query.setFacet(true);
    query.setFacetLimit(-1);
    query.setFacetMinCount(1);
    query.setRows(0);
    query.addFacetField(StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME);

    try {
        QueryResponse response = solr.query(query);
        TreeMap<String, Long> res = new TreeMap<>();
        res.putAll(getFacets(response).get(StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME));
        return res;
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:uk.ac.ebi.phenotype.service.StatisticalResultService.java

License:Apache License

public Map<String, Set<String>> getAccessionProceduresMap(String resourceName) {

    SolrQuery query = new SolrQuery();
    Map<String, Set<String>> res = new HashMap<>();
    NamedList<List<PivotField>> response;

    if (resourceName == null) {
        query.setQuery("*:*");
    } else {/* ww  w . jav a  2s .  c o  m*/
        query.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + resourceName);
    }
    query.setFacet(true);
    query.addFacetPivotField(
            StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID);
    query.setFacetLimit(-1);
    query.setFacetMinCount(1);
    query.setRows(0);

    try {
        response = solr.query(query).getFacetPivot();
        for (PivotField genePivot : response.get(
                StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID)) {
            String geneName = genePivot.getValue().toString();
            Set<String> procedures = new HashSet<>();
            for (PivotField f : genePivot.getPivot()) {
                procedures.add(f.getValue().toString());
            }
            res.put(geneName, procedures);
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return res;
}

From source file:uk.ac.ebi.phenotype.service.StatisticalResultService.java

License:Apache License

public Set<String> getAccessionsByResourceName(String resourceName) {

    Set<String> res = new HashSet<>();
    SolrQuery query = new SolrQuery().setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + resourceName);
    query.setFacet(true);/*from   www.j a v a 2s . c om*/
    query.addFacetField(StatisticalResultDTO.MARKER_ACCESSION_ID);
    query.setFacetLimit(10000000);
    query.setFacetMinCount(1);
    query.setRows(0);

    QueryResponse response;
    try {
        response = solr.query(query);
        for (Count id : response.getFacetField(StatisticalResultDTO.MARKER_ACCESSION_ID).getValues()) {
            res.add(id.getName());
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return res;
}