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

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

Introduction

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

Prototype

public SolrQuery setFacet(boolean b) 

Source Link

Document

enable/disable faceting.

Usage

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);
    q.setFacetMinCount(1);// www . j  a va  2s.c  om
    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

public Map<String, Long> getColoniesNoMPHit(ArrayList<String> resourceName, ZygosityType zygosity)
        throws SolrServerException {
    Map<String, Long> res = new HashMap<>();
    Long time = System.currentTimeMillis();
    SolrQuery q = new SolrQuery();

    if (resourceName != null) {
        q.setQuery(GenotypePhenotypeDTO.RESOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + GenotypePhenotypeDTO.RESOURCE_NAME + ":"));
    } else {//from   w  w w. j a  v a 2  s.c  o m
        q.setQuery("*:*");
    }

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

    q.addFilterQuery(GenotypePhenotypeDTO.P_VALUE + ":[" + this.P_VALUE_THRESHOLD + " TO 1]");

    q.addFacetField(StatisticalResultDTO.COLONY_ID);
    q.setFacetMinCount(1);
    q.setFacet(true);
    q.setRows(1);
    q.set("facet.limit", -1);

    System.out.println("Solr url for getColoniesNoMPHit " + solr.getBaseURL() + "/select?" + q);
    QueryResponse response = solr.query(q);

    for (Count facet : response.getFacetField(StatisticalResultDTO.COLONY_ID).getValues()) {
        String value = facet.getName();
        long count = facet.getCount();
        res.put(value, count);
    }

    System.out.println("Done in " + (System.currentTimeMillis() - time));
    return res;

}

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

License:Apache License

public Map<String, ArrayList<String>> getDistributionOfLinesByMPTopLevel(ArrayList<String> resourceName,
        Float pValueThreshold) throws SolrServerException, InterruptedException, ExecutionException {

    Map<String, ArrayList<String>> res = new ConcurrentHashMap<>(); //<parameter, <genes>>
    Long time = System.currentTimeMillis();
    String pivotFacet = StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME + "," + StatisticalResultDTO.COLONY_ID;
    SolrQuery q = new SolrQuery();

    if (resourceName != null) {
        q.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + StatisticalResultDTO.RESOURCE_NAME + ":"));
    } else {//from  w  w  w. j a va2s  . c  o m
        q.setQuery("*:*");
    }

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

    q.set("facet.pivot", pivotFacet);
    q.setFacet(true);
    q.setFacetMinCount(1);
    q.setRows(1);
    q.set("facet.limit", -1);

    System.out.println("Solr url for getDistributionOfLinesByMPTopLevel " + solr.getBaseURL() + "/select?" + q);
    QueryResponse response = solr.query(q);

    for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) {
        ArrayList<String> colonies = new ArrayList<>();
        for (PivotField colony : pivot.getPivot()) {
            colonies.add(colony.getValue().toString());
        }
        res.put(pivot.getValue().toString(), new ArrayList<String>(colonies));
    }

    System.out.println("Done in " + (System.currentTimeMillis() - time));
    return res;
}

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

License:Apache License

public Map<String, ArrayList<String>> getDistributionOfGenesByMPTopLevel(ArrayList<String> resourceName,
        Float pValueThreshold) throws SolrServerException, InterruptedException, ExecutionException {

    Map<String, ArrayList<String>> res = new ConcurrentHashMap<>(); //<parameter, <genes>>
    Long time = System.currentTimeMillis();
    String pivotFacet = StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME + ","
            + StatisticalResultDTO.MARKER_ACCESSION_ID;
    SolrQuery q = new SolrQuery();

    if (resourceName != null) {
        q.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + StatisticalResultDTO.RESOURCE_NAME + ":"));
    } else {/* ww  w  . j  a  v a  2 s. com*/
        q.setQuery("*:*");
    }

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

    q.set("facet.pivot", pivotFacet);
    q.setFacet(true);
    q.setRows(1);
    q.set("facet.limit", -1);

    System.out.println("Solr url for getDistributionOfGenesByMPTopLevel " + solr.getBaseURL() + "/select?" + q);
    QueryResponse response = solr.query(q);

    for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) {
        ArrayList<String> genes = new ArrayList<>();
        for (PivotField gene : pivot.getPivot()) {
            genes.add(gene.getValue().toString());
        }
        res.put(pivot.getValue().toString(), new ArrayList<String>(genes));
    }

    System.out.println("Done in " + (System.currentTimeMillis() - time));
    return res;
}

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 va2  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 {//w w  w.j av  a  2s.c om
        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 PhenotypeFacetResult getPhenotypeFacetResultByPhenotypingCenterAndPipeline(String phenotypingCenter,
        String pipelineStableId) throws IOException, URISyntaxException {

    System.out.println("DOING PHEN CALL SUMMARY RESULTS FROM SRS");
    SolrQuery query = new SolrQuery();
    query.setQuery(StatisticalResultDTO.PHENOTYPING_CENTER + ":\"" + phenotypingCenter);
    query.addFilterQuery(StatisticalResultDTO.PIPELINE_STABLE_ID + ":" + pipelineStableId);
    query.setFacet(true);
    query.addFacetField(StatisticalResultDTO.RESOURCE_FULLNAME);
    query.addFacetField(StatisticalResultDTO.PROCEDURE_NAME);
    query.addFacetField(StatisticalResultDTO.MARKER_SYMBOL);
    query.addFacetField(StatisticalResultDTO.MP_TERM_NAME);
    query.set("sort", "p_value asc");
    query.setRows(10000000);//from  www .  j  a va2s.c om
    query.set("wt", "json");
    query.set("version", "2.2");

    String solrUrl = solr.getBaseURL() + "/select?" + query;
    return gpService.createPhenotypeResultFromSolrResponse(solrUrl, false);
}

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);
    query.addFacetField(StatisticalResultDTO.MARKER_ACCESSION_ID);
    query.setFacetLimit(10000000);// ww w . j  ava  2  s .  com
    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;
}

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

License:Apache License

/**
 * This map is needed for the summary on phenotype pages (the percentages &
 * pie chart). It takes a long time to load so it does it asynchronously.
 * /*w w w.  j  a  v a  2 s .  c o  m*/
 * @param sex
 * @return Map < String parameterStableId , ArrayList<String
 *         geneMgiIdWithParameterXMeasured>>
 * @throws SolrServerException
 * @throws InterruptedException
 * @throws ExecutionException
 * @author tudose
 */
public Map<String, ArrayList<String>> getParameterToGeneMap(SexType sex)
        throws SolrServerException, InterruptedException, ExecutionException {

    Map<String, ArrayList<String>> res = new ConcurrentHashMap<>(); //<parameter, <genes>>
    Long time = System.currentTimeMillis();
    String pivotFacet = StatisticalResultDTO.PARAMETER_STABLE_ID + ","
            + StatisticalResultDTO.MARKER_ACCESSION_ID;
    SolrQuery q = new SolrQuery().setQuery(ObservationDTO.SEX + ":" + sex.name());
    q.setFilterQueries(StatisticalResultDTO.STRAIN_ACCESSION_ID + ":\""
            + StringUtils.join(OverviewChartsController.OVERVIEW_STRAINS,
                    "\" OR " + ObservationDTO.STRAIN_ACCESSION_ID + ":\"")
            + "\"");
    q.set("facet.pivot", pivotFacet);
    q.setFacet(true);
    q.setRows(1);
    q.set("facet.limit", -1);

    System.out.println("Solr url for getParameterToGeneMap " + solr.getBaseURL() + "/select?" + q);
    QueryResponse response = solr.query(q);

    for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) {
        ArrayList<String> genes = new ArrayList<>();
        for (PivotField gene : pivot.getPivot()) {
            genes.add(gene.getValue().toString());
        }
        res.put(pivot.getValue().toString(), new ArrayList<String>(genes));
    }

    System.out.println("Done in " + (System.currentTimeMillis() - time));
    return res;
}

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

License:Apache License

public void addGenesForBothSexes() throws SolrServerException, InterruptedException, ExecutionException {

    Long time = System.currentTimeMillis();
    String pivotFacet = StatisticalResultDTO.PARAMETER_STABLE_ID + ","
            + StatisticalResultDTO.MARKER_ACCESSION_ID;
    SolrQuery q = new SolrQuery().setQuery("-" + ObservationDTO.SEX + ":*");
    q.setFilterQueries(StatisticalResultDTO.STRAIN_ACCESSION_ID + ":\""
            + StringUtils.join(OverviewChartsController.OVERVIEW_STRAINS,
                    "\" OR " + ObservationDTO.STRAIN_ACCESSION_ID + ":\"")
            + "\"");
    q.set("facet.pivot", pivotFacet);
    q.setFacet(true);
    q.setRows(1);//  w  w  w.  j a  va2 s  .  c o m
    q.set("facet.limit", -1);

    QueryResponse response = solr.query(q);
    System.out.println("Solr url for getParameterToGeneMap " + solr.getBaseURL() + "/select?" + q);

    for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) {
        ArrayList<String> genes = new ArrayList<>();
        for (PivotField gene : pivot.getPivot()) {
            genes.add(gene.getValue().toString());
        }
        maleParamToGene.put(pivot.getValue().toString(), new ArrayList<String>(genes));
        femaleParamToGene.put(pivot.getValue().toString(), new ArrayList<String>(genes));
    }

    System.out.println("Done in " + (System.currentTimeMillis() - time));
}