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

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

Introduction

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

Prototype

public SolrQuery setRows(Integer rows) 

Source Link

Usage

From source file:org.memex.GunAdsParser.java

License:Apache License

public void getAds(String modelFilePath, int start) throws SolrServerException, IOException {
    File modelFile = new File(modelFilePath);

    // Construct a SolrQuery
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.setFields("content", "id");
    query.addFilterQuery(fq);//from  w  ww .j  a  v a  2  s  . c om
    query.setStart(start);
    query.setRows(rows);

    QueryResponse rsp = this.solrCore.query(query);
    SolrDocumentList list = rsp.getResults();

    SentimentModel model = new SentimentModel(modelFile);
    SentimentME sentiment = new SentimentME(model);

    while (list.getNumFound() > list.getStart() + rows) {
        long index = list.getStart();
        for (SolrDocument doc : list) {
            String result = sentiment.predict((doc.getFieldValue("content")).toString());
            SolrInputDocument document = new SolrInputDocument();
            Map<String, Object> operation = new HashMap<>();
            operation.put("set", result);
            document.addField("id", doc.getFieldValue("id"));
            document.addField("sentiment_s_md", operation);
            System.out.println(doc.getFieldValue("id"));
            solrCore.add(document);
            solrCore.commit();
            if (true) {
                return;
            }
            System.out.println(index + ": " + result);
            index++;
        }
        //commit
        solrCore.commit();
        if (list.getNumFound() > list.getStart() + rows) {
            query.setStart((int) (list.getStart() + rows));
            rsp = this.solrCore.query(query);
            list = rsp.getResults();
        }
    }

}

From source file:org.mousephenotype.cda.indexers.AlleleIndexer.java

License:Apache License

@Override
public RunStatus run() throws IndexerException {
    int count = 0;
    long rows = 0;
    RunStatus runStatus = new RunStatus();
    long start = System.currentTimeMillis();

    try (Connection connection = komp2DataSource.getConnection()) {

        // this query would only pick up lines that imits have phenotype / production status info about
        SolrQuery query = new SolrQuery("latest_project_status:*");
        query.addFilterQuery("feature_type:* AND type:(gene OR Gene)");

        query.setRows(BATCH_SIZE);

        populateStatusLookup();//from   w ww . jav a 2s.  c  om
        logger.info(" Added {} total status lookup beans", sangerAlleleBeanByMgiGeneAccessionId.size());

        populateHumanSymbolLookup();
        logger.info(" Added {} total human symbol lookup beans", humanSymbolLookupByMgiGeneAccessionId.size());

        populateDiseaseLookup();
        logger.info(" Added {} total disease lookup beans", diseaseBeanByMgiGeneAccessionId.size());

        populateLegacyLookup(connection, runStatus);
        logger.info(" Added {} total legacy project lookup beans", legacyProjectByMgiGeneAccessionId.size());

        populateMgiGeneId2EnsemblGeneId(connection);
        logger.info(" Added {} total Ensembl id to MGI gene id lookup beans",
                ensembleGeneIdByMgiGeneAccessionId.size());

        alleleCore.deleteByQuery("*:*");
        alleleCore.commit();

        while (count <= rows) {
            query.setStart(count);
            QueryResponse response = allele2Core.query(query);
            rows = response.getResults().getNumFound();
            List<SangerGeneBean> sangerGenes = response.getBeans(SangerGeneBean.class);

            // Convert to Allele DTOs
            Map<String, AlleleDTO> alleles = convertSangerGeneBeans(sangerGenes);

            // Look up the marker synonyms
            lookupMarkerSynonyms(connection, alleles, runStatus);

            // Look up ensembl id to MGI gene id mapping
            lookupMgiGeneId2EnsemblGeneId(alleles);

            // Look up the human mouse symbols
            lookupHumanMouseSymbols(alleles);

            // Look up the ES cell status
            lookupEsCellStatus(alleles);

            // Look up the disease data
            lookupDiseaseData(alleles);

            // Now index the alleles
            expectedDocumentCount += alleles.size();
            indexAlleles(alleles);

            count += BATCH_SIZE;
        }

        alleleCore.commit();

    } catch (SQLException | IOException | SolrServerException e) {
        e.printStackTrace();
        throw new IndexerException(e);
    }

    logger.info(" Added {} total beans in {}", expectedDocumentCount,
            commonUtils.msToHms(System.currentTimeMillis() - start));
    return runStatus;
}

From source file:org.mousephenotype.cda.indexers.AlleleIndexer.java

License:Apache License

private void populateStatusLookup() throws SolrServerException, IOException {

    SolrQuery query = new SolrQuery("*:*");
    query.setRows(Integer.MAX_VALUE);
    query.addFilterQuery("type:Allele");

    QueryResponse response = allele2Core.query(query);
    List<SangerAlleleBean> sangerAlleles = response.getBeans(SangerAlleleBean.class);
    for (SangerAlleleBean allele : sangerAlleles) {
        if (!sangerAlleleBeanByMgiGeneAccessionId.containsKey(allele.getMgiAccessionId())) {
            sangerAlleleBeanByMgiGeneAccessionId.put(allele.getMgiAccessionId(),
                    new ArrayList<SangerAlleleBean>());
        }//  w  w w . j a  v  a  2s .co  m
        sangerAlleleBeanByMgiGeneAccessionId.get(allele.getMgiAccessionId()).add(allele);
    }
}

From source file:org.mousephenotype.cda.indexers.AlleleIndexer.java

License:Apache License

private void populateDiseaseLookup() throws SolrServerException, IOException {

    int docsRetrieved = 0;
    int numDocs = getDiseaseDocCount();

    // Fields in the solr core to bring back
    String fields = StringUtils.join(Arrays.asList(DiseaseBean.DISEASE_ID, DiseaseBean.MGI_ACCESSION_ID,
            DiseaseBean.DISEASE_SOURCE, DiseaseBean.DISEASE_TERM, DiseaseBean.DISEASE_ALTS,
            DiseaseBean.DISEASE_CLASSES, DiseaseBean.HUMAN_CURATED, DiseaseBean.MOUSE_CURATED,
            DiseaseBean.MGI_PREDICTED, DiseaseBean.IMPC_PREDICTED, DiseaseBean.MGI_PREDICTED_KNOWN_GENE,
            DiseaseBean.IMPC_PREDICTED_KNOWN_GENE, DiseaseBean.MGI_NOVEL_PREDICTED_IN_LOCUS,
            DiseaseBean.IMPC_NOVEL_PREDICTED_IN_LOCUS), ",");

    // The solrcloud instance cannot give us all results back at once,
    // we must batch up the calls and build it up piece at a time
    while (docsRetrieved < numDocs + PHENODIGM_BATCH_SIZE) {

        SolrQuery query = new SolrQuery("*:*");
        query.addFilterQuery("type:disease_gene_summary");
        query.setFields(fields);/*from w w  w  . ja  v  a2s .  com*/
        query.setStart(docsRetrieved);
        query.setRows(PHENODIGM_BATCH_SIZE);
        query.setSort(DiseaseBean.DISEASE_ID, SolrQuery.ORDER.asc);

        QueryResponse response = phenodigmCore.query(query);
        if (response == null) {
            throw new SolrServerException(
                    "Response from phendigm core is null. Chcek phenodigm core is up with query: " + query);
        }
        List<DiseaseBean> diseases = response.getBeans(DiseaseBean.class);
        for (DiseaseBean disease : diseases) {
            if (!diseaseBeanByMgiGeneAccessionId.containsKey(disease.getMgiAccessionId())) {
                diseaseBeanByMgiGeneAccessionId.put(disease.getMgiAccessionId(), new ArrayList<DiseaseBean>());
            }
            diseaseBeanByMgiGeneAccessionId.get(disease.getMgiAccessionId()).add(disease);
        }

        docsRetrieved += PHENODIGM_BATCH_SIZE;
    }
}

From source file:org.mousephenotype.cda.indexers.AlleleIndexer.java

License:Apache License

private int getDiseaseDocCount() throws SolrServerException, IOException {

    SolrQuery query = new SolrQuery("*:*");
    query.setRows(0);
    query.addFilterQuery("type:disease_gene_summary");

    QueryResponse response = phenodigmCore.query(query);
    return (int) response.getResults().getNumFound();
}

From source file:org.mousephenotype.cda.indexers.MPIndexer.java

License:Apache License

private RunStatus populateMpCallMaps(Map<String, Synonym> synonyms)
        throws IOException, SolrServerException, URISyntaxException, JSONException {
    RunStatus status = new RunStatus();

    List<SolrClient> ss = new ArrayList<>();

    ss.add(genotypePhenotypeCore);//from  ww  w  . ja  v a  2  s  .c  o  m

    for (int i = 0; i < ss.size(); i++) {

        SolrClient solrSvr = ss.get(i);
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        query.setFacet(true);
        query.setRows(0);
        query.addFacetField(GenotypePhenotypeDTO.MP_TERM_ID);
        query.addFacetField(GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID);
        query.addFacetField(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID);
        query.setFacetLimit(-1);

        for (FacetField facetGroup : solrSvr.query(query).getFacetFields()) {
            for (FacetField.Count facet : facetGroup.getValues()) {
                if (!mpCalls.containsKey(facet.getName())) {
                    mpCalls.put(facet.getName(), new Long(0));

                    Map<String, Integer> geneVariantCount = getPhenotypeGeneVariantCounts(facet.getName(),
                            status, synonyms);
                    int gvCount = geneVariantCount.get("sumCount");
                    mpGeneVariantCount.put(facet.getName(), gvCount);
                }
                mpCalls.put(facet.getName(), facet.getCount() + mpCalls.get(facet.getName()));

            }
        }
    }

    return status;
}

From source file:org.mousephenotype.cda.solr.repositories.image.ImagesSolrJ.java

License:Apache License

private SolrDocumentList runQuery(String query, int start, int length) throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();

    log.debug("solr query=" + query);
    solrQuery.setQuery(query);//from  w  ww  . jav a2 s.  c o m
    solrQuery.setStart(start);
    solrQuery.setRows(length);
    solrQuery.setFields("id");

    QueryResponse rsp = null;
    rsp = sangerImagesCore.query(solrQuery);

    return rsp.getResults();
}

From source file:org.mousephenotype.cda.solr.repositories.image.ImagesSolrJ.java

License:Apache License

private QueryResponse runFacetQuery(String query, String facetField, int start, int length, String filterQuery)
        throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(query);/*from   w  w w .  j  a  va  2  s .co  m*/
    solrQuery.setStart(start);
    solrQuery.setRows(length);
    solrQuery.setFacet(true);
    solrQuery.setFacetMinCount(1);
    solrQuery.addFacetField(facetField);
    if (filterQuery != "") {
        solrQuery.addFilterQuery(filterQuery);
    }

    return sangerImagesCore.query(solrQuery);

}

From source file:org.mousephenotype.cda.solr.repositories.image.ImagesSolrJ.java

License:Apache License

public QueryResponse getDocsForGeneWithFacetField(String geneId, String facetName, String facetValue,
        String filterQuery, int start, int length) throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();

    String processedGeneId = processQuery(geneId);
    String query = "accession:" + processedGeneId;

    solrQuery.setQuery(query);//from  w w  w  .  ja  va 2 s .  com
    solrQuery.setStart(start);
    solrQuery.setRows(length);

    // need to add quotes around so that spaces are allowed
    String facetQuery = facetName + ":" + processValueForSolr(facetValue);
    solrQuery.addFilterQuery(facetQuery);

    log.debug("facet name and val====" + facetQuery);

    if (filterQuery != "") {
        solrQuery.addFilterQuery(filterQuery);
    }

    return sangerImagesCore.query(solrQuery);
}

From source file:org.mousephenotype.cda.solr.repositories.image.ImagesSolrJ.java

License:Apache License

/**
 * @since 2016/02/25//from   w  ww .  j a  v a 2s  .c om
 * @author ilinca
 * @return
 * @throws SolrServerException, IOException
 */
public SolrDocumentList getImagesForLacZ() throws SolrServerException, IOException {

    SolrQuery query = new SolrQuery();
    query.setQuery("procedure_name:*LacZ*");
    query.addFilterQuery("ma_id:*");
    query.addFilterQuery("accession:*");
    query.addField("ma_id");
    query.addField("accession");
    query.setRows(Integer.MAX_VALUE);
    return sangerImagesCore.query(query).getResults();
}