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

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

Introduction

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

Prototype

public ModifiableSolrParams set(String name, String... val) 

Source Link

Document

Replace any existing parameter with the given name.

Usage

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  ww  w . ja v a2s . co 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 {/*from ww  w .  jav  a  2 s.c  om*/
        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

public Map<String, List<StatisticalResultBean>> getPvaluesByAlleleAndPhenotypingCenterAndPipeline(
        String alleleAccession, String phenotypingCenter, String pipelineStableId,
        List<String> procedureStableIds, ArrayList<String> resource)
        throws NumberFormatException, SolrServerException {

    Map<String, List<StatisticalResultBean>> results = new HashMap<String, List<StatisticalResultBean>>();
    SolrQuery query = new SolrQuery();

    query.setQuery(StatisticalResultDTO.PHENOTYPING_CENTER + ":\"" + phenotypingCenter + "\" AND "
            + StatisticalResultDTO.PIPELINE_STABLE_ID + ":" + pipelineStableId + " AND "
            + StatisticalResultDTO.ALLELE_ACCESSION_ID + ":\"" + alleleAccession + "\"");
    if (procedureStableIds != null) {
        query.addFilterQuery("(" + StatisticalResultDTO.PROCEDURE_STABLE_ID + ":"
                + StringUtils.join(procedureStableIds, " OR " + StatisticalResultDTO.PROCEDURE_STABLE_ID + ":")
                + ")");
    }/*  ww  w .  j av a2 s  .com*/
    if (resource != null) {
        query.addFilterQuery("(" + StatisticalResultDTO.RESOURCE_NAME + ":"
                + StringUtils.join(resource, " OR " + StatisticalResultDTO.RESOURCE_NAME + ":") + ")");
    }
    query.setRows(Integer.MAX_VALUE);
    query.addField(StatisticalResultDTO.P_VALUE).addField(StatisticalResultDTO.EFFECT_SIZE)
            .addField(StatisticalResultDTO.STATUS).addField(StatisticalResultDTO.STATISTICAL_METHOD)
            .addField(StatisticalResultDTO.ZYGOSITY).addField(StatisticalResultDTO.MALE_CONTROL_COUNT)
            .addField(StatisticalResultDTO.MALE_MUTANT_COUNT)
            .addField(StatisticalResultDTO.FEMALE_CONTROL_COUNT)
            .addField(StatisticalResultDTO.FEMALE_MUTANT_COUNT)
            .addField(StatisticalResultDTO.PARAMETER_STABLE_ID).addField(StatisticalResultDTO.METADATA_GROUP);
    query.set("sort", StatisticalResultDTO.P_VALUE + " asc");

    for (SolrDocument doc : solr.query(query).getResults()) {
        String parameterStableId = doc.getFieldValue(StatisticalResultDTO.PARAMETER_STABLE_ID).toString();
        List<StatisticalResultBean> lb = null;

        if (results.containsKey(parameterStableId)) {
            lb = results.get(parameterStableId);
        } else {
            lb = new ArrayList<StatisticalResultBean>();
            results.put(parameterStableId, lb);
        }

        Double effectSize = doc.containsKey(StatisticalResultDTO.EFFECT_SIZE)
                ? Double.parseDouble(doc.getFieldValue(StatisticalResultDTO.EFFECT_SIZE).toString())
                : 1000000000;
        String status = doc.containsKey(StatisticalResultDTO.STATUS)
                ? doc.getFieldValue(StatisticalResultDTO.STATUS).toString()
                : "no status found";

        lb.add(new StatisticalResultBean(
                Double.parseDouble(doc.getFieldValue(StatisticalResultDTO.P_VALUE).toString()), effectSize,
                status, doc.getFieldValue(StatisticalResultDTO.STATISTICAL_METHOD).toString(), "don't know",
                doc.getFieldValue(StatisticalResultDTO.ZYGOSITY).toString(),
                Integer.parseInt(doc.getFieldValue(StatisticalResultDTO.MALE_CONTROL_COUNT).toString()),
                Integer.parseInt(doc.getFieldValue(StatisticalResultDTO.MALE_MUTANT_COUNT).toString()),
                Integer.parseInt(doc.getFieldValue(StatisticalResultDTO.FEMALE_CONTROL_COUNT).toString()),
                Integer.parseInt(doc.getFieldValue(StatisticalResultDTO.FEMALE_MUTANT_COUNT).toString()),
                doc.getFieldValue(StatisticalResultDTO.METADATA_GROUP).toString()));
    }

    return results;

}

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);/*from  w w w .j  a  v  a  2s . c o m*/
    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);
    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

/**
 * 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.
 * //from ww w  .  j ava2 s .  com
 * @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);/*from w  w  w  .  j  av  a 2s  .  c o  m*/
    q.setRows(1);
    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));
}

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

License:Apache License

public List<Group> getGenesBy(String mpId, String sex) throws SolrServerException {

    SolrQuery q = new SolrQuery().setQuery("(" + StatisticalResultDTO.MP_TERM_ID + ":\"" + mpId + "\" OR "
            + StatisticalResultDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + mpId + "\" OR "
            + StatisticalResultDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + mpId + "\")").setRows(10000);
    q.set("group.field", "" + StatisticalResultDTO.MARKER_SYMBOL);
    q.set("group", true);
    q.set("group.limit", 0);

    if (sex != null) {
        q.addFilterQuery(GenotypePhenotypeDTO.SEX + ":" + sex);
    }//from w  w  w . j  ava  2s. co m
    QueryResponse results = solr.query(q);
    return results.getGroupResponse().getValues().get(0).getValues();
}

From source file:uk.ac.ebi.phis.service.AutosuggestService.java

License:Apache License

public String getAutosuggest(String term, AutosuggestTypes type, String stage, String imagingMethod,
        String taxon, String sampleType, String imageGeneratedBy, Integer rows) {

    SolrQuery solrQuery = buildAutosuggestQuery(term, type, stage, imagingMethod, taxon, sampleType,
            imageGeneratedBy, rows);/*from  w  ww  . j a  v a2  s .  c om*/
    ArrayList<String> suggestions = new ArrayList<>();

    solrQuery.set("group", true);
    solrQuery.set("group.field", "term_autosuggest_na");

    System.out.println("Solr URL : " + solr.getBaseURL() + "/select?" + solrQuery);
    log.info("Solr URL in getImages : " + solr.getBaseURL() + "/select?" + solrQuery);

    try {

        List<Group> groups = solr.query(solrQuery).getGroupResponse().getValues().get(0).getValues();
        for (Group group : groups) {
            suggestions.add(group.getGroupValue());
        }

    } catch (SolrServerException e) {
        e.printStackTrace();
    }

    JSONObject returnObj = new JSONObject();
    returnObj.put("response", new JSONObject().put("suggestions", new JSONArray(suggestions)));
    return returnObj.toString().replaceAll("<\\\\", "<");
}

From source file:uk.ac.ebi.phis.service.AutosuggestService.java

License:Apache License

private SolrQuery buildAutosuggestQuery(String term, AutosuggestTypes type, String stage, String imagingMethod,
        String taxon, String sampleType, String imageGeneratedBy, Integer rows) {

    SolrQuery solrQuery = new SolrQuery();

    term = handleSpecialCharacters(term);
    imagingMethod = handleSpecialCharacters(imagingMethod);
    taxon = handleSpecialCharacters(taxon);
    sampleType = handleSpecialCharacters(sampleType);
    imageGeneratedBy = handleSpecialCharacters(imageGeneratedBy);

    solrQuery.setQuery(term);/*from w w w.  java  2  s .co m*/
    solrQuery.setFields(ImageDTO.TERM_AUTOSUGGEST);
    solrQuery.set("defType", "edismax");
    solrQuery.set("qf", "term_autosuggest term_autosuggest_ws term_autosuggest_e term_autosuggest_na");
    solrQuery.set("bq", "term_autosuggest_ws:\"" + term + "\"^10 term_autosuggest_e:\"" + term
            + "\"^100 term_autosuggest_na:\"" + term + "\"^1000 term_autosuggest:\"" + term + "\"^1");
    solrQuery.setRows(rows); // number of groups to return (not result documents)

    if (type != null) {
        solrQuery.addFilterQuery(AutosuggestDTO.AUTOSUGGEST_TYPE + ":" + type);
    }
    if (stage != null) {
        solrQuery.addFilterQuery(AutosuggestDTO.STAGE + ":\"" + stage + "\"");
    }
    if (taxon != null) {
        solrQuery.addFilterQuery(AutosuggestDTO.TAXON + ":\"" + taxon + "\"");
    }
    if (sampleType != null) {
        solrQuery.addFilterQuery(AutosuggestDTO.SAMPLE_TYPE + ":\"" + sampleType + "\"");
    }
    if (imagingMethod != null) {
        solrQuery.addFilterQuery(AutosuggestDTO.IMAGING_METHOD + ":\"" + imagingMethod + "\"");
    }
    if (imageGeneratedBy != null) {
        solrQuery.addFilterQuery(AutosuggestDTO.IMAGE_GENERATED_BY + ":\"" + imageGeneratedBy + "\"");
    }

    return solrQuery;
}

From source file:uk.ac.ebi.phis.service.ChannelService.java

License:Apache License

public ChannelDTO getChannelBean(String channelId) {
    ChannelDTO channel = null;/*from   w  ww  .ja v  a 2  s.  co m*/

    SolrQuery solrQuery = new SolrQuery();
    channelId = handleSpecialCharacters(channelId);
    solrQuery.setQuery(ChannelDTO.ID + ":\"" + channelId + "\"");
    solrQuery.set("wt", "json");
    try {
        QueryResponse result = solr.query(solrQuery);
        if (result.getBeans(ChannelDTO.class).size() > 0) {
            // should have only one anyway as ids are unique
            channel = result.getBeans(ChannelDTO.class).get(0);
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return channel;
}