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

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

Introduction

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

Prototype

public SolrQuery setQuery(String query) 

Source Link

Usage

From source file:org.kuali.ole.docstore.discovery.service.IndexerService_UT.java

License:Open Source License

protected List<String> getUUIDsByAuthor(String authorName) throws Exception {
    List<String> uuidList = new ArrayList<String>();
    SolrServer solr = SolrServerManager.getInstance().getSolrServer();
    SolrQuery query = new SolrQuery();
    query.setQuery("Author_display:" + authorName);
    QueryResponse queryResponse = solr.query(query);
    Iterator<SolrDocument> iter = queryResponse.getResults().iterator();
    while (iter.hasNext()) {
        SolrDocument resultDoc = iter.next();
        String id = (String) resultDoc.getFieldValue("id");
        uuidList.add(id);//from ww  w  .  j a  v  a 2  s .c o m
        LOG.info("uuidList=" + uuidList);
    }
    return uuidList;
}

From source file:org.kuali.ole.docstore.discovery.service.IndexerService_UT.java

License:Open Source License

public QueryResponse searchRecord(String docCat, String docType, String docFormat, String fieldName,
        String fieldValue) throws Exception {
    LOG.info("fieldNameIdentifier " + fieldName);
    String identifier_args = "(" + fieldName + ":" + fieldValue + ")";
    String docCategory_args = "(DocCategory" + ":" + docCat + ")";
    String docType_args = "(DocType" + ":" + docType + ")";
    String docFormat_args = "(DocFormat" + ":" + docFormat + ")";
    String args = identifier_args + "AND" + docCategory_args + "AND" + docType_args + "AND" + docFormat_args;
    //SolrServer solr = new CommonsHttpSolrServer(PropertyUtil.getPropertyUtil().getProperty("docSearchURL") + "bib");
    SolrServer solr = SolrServerManager.getInstance().getSolrServer();
    SolrQuery query = new SolrQuery();
    LOG.info("args " + args);
    query.setQuery(args);
    //query.setQuery(docCategory_args);
    //query.setQuery(docType_args);
    //query.setQuery(docFormat_args);
    //LOG.info("getQuery "+query.getQuery());

    QueryResponse response = solr.query(query);
    // LOG.info("response "+response);
    return response;
}

From source file:org.kuali.ole.docstore.engine.service.rest.DocstoreRestClient_UT.java

License:Open Source License

public void searchBibWithFacets(String facetSort) throws Exception {
    String[] facets = { "Author_facet", "Format_facet", "Genre_facet", "Language_facet",
            "PublicationDate_facet", "PublicationDate_sort" };
    String[] fieldList = { "LocalId_display", "Title_sort", "Title_display", "JournalTitle_display",
            "Author_display", "Publisher_display", "ISBN_display", "ISSN_display", "Subject_display",
            "Publisher_display", "PublicationDate_display", "Edition_display", "Format_display",
            "Language_display", "Description_display", "FormGenre_display", "DocFormat", "staffOnlyFlag",
            "bibIdentifier", "holdingsIdentifier" };
    String args = "(DocType:bibliographic)AND((*:*))";
    SolrServer solr = SolrServerManager.getInstance().getSolrServer();
    SolrQuery query = new SolrQuery();
    query.setQuery(args);
    query.setFacet(true);/*  www.  j av a2s.c o m*/
    query.addFacetField(facets);
    query.setFacetMinCount(1);
    query.setFacetSort(facetSort);
    query.setFacetLimit(5);
    query.setFields(fieldList);
    query.set("facet.offset", "0");
    QueryResponse response = solr.query(query);
    System.out.println("Search result count " + response.getResults().getNumFound()
            + " and  time taken to search is " + response.getQTime());
}

From source file:org.lilyproject.lilyservertestfw.test.KeepDataTest.java

License:Apache License

private List<RecordId> querySolr(String name) throws SolrServerException {
    SolrServer solr = lilyProxy.getSolrProxy().getSolrServer();
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.set("df", "name");
    solrQuery.setQuery(name);
    solrQuery.set("fl", "lily.id");

    QueryResponse response = solr.query(solrQuery);
    // Convert query result into a list of record IDs
    SolrDocumentList solrDocumentList = response.getResults();
    List<RecordId> recordIds = new ArrayList<RecordId>();
    for (SolrDocument solrDocument : solrDocumentList) {
        String recordId = (String) solrDocument.getFirstValue("lily.id");
        recordIds.add(repository.getIdGenerator().fromString(recordId));
    }/* w w w. j a  va2 s .c  o m*/
    return recordIds;
}

From source file:org.lilyproject.lilyservertestfw.test.LilyProxyTest.java

License:Apache License

private List<RecordId> querySolr(String name) throws SolrServerException, IOException {
    SolrServer solr = lilyProxy.getSolrProxy().getSolrServer();
    solr.commit();//  w w  w  .j  ava 2 s . c o  m
    SolrQuery solrQuery = new SolrQuery();
    //set default search field (no longer supported in schema.xml
    solrQuery.set("df", "name");
    solrQuery.setQuery(name);
    solrQuery.set("fl", "lily.id");
    QueryResponse response = solr.query(solrQuery);
    // Convert query result into a list of record IDs
    SolrDocumentList solrDocumentList = response.getResults();
    List<RecordId> recordIds = new ArrayList<RecordId>();
    for (SolrDocument solrDocument : solrDocumentList) {
        String recordId = (String) solrDocument.getFirstValue("lily.id");
        recordIds.add(repository.getIdGenerator().fromString(recordId));
    }
    return recordIds;
}

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 av a  2s . co m*/
    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.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   w  ww .  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.indexers.StatisticalResultsIndexer.java

License:Apache License

/**
 * Check to see if the count of documents we think have been added actually matches
 * the number of documents in solr//w  w w .j a va2s  .c om
 *
 * @param count the number of documents that should have been added
 */
private void checkSolrCount(Integer count) throws SolrServerException, IOException {

    SolrQuery query = new SolrQuery();
    query.setQuery("*:*").setRows(0);
    QueryResponse response = statisticalResultCore.query(query);
    Long solrCount = response.getResults().getNumFound();

    logger.info("  Count of documents in solr: {}, count added by indexer: {}, Difference: {}", solrCount,
            count, count - solrCount);

    if (count - solrCount > 0) {

        // The java Set.add() method returns false when attempting to add an element that already exists in
        // the set so the filter will remove all non-duplicate elements leaving only those document IDs that
        // have been added twice
        Set<String> uniques = new HashSet<>();
        Set<String> diff = shouldHaveAdded.stream().filter(e -> !uniques.add(e)).collect(Collectors.toSet());

        logger.warn(" Should have added these {} doc IDs, but missing from solr {}", diff.size(),
                StringUtils.join(diff, ", "));
    }

}

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);
    solrQuery.setStart(start);/*w  ww  .jav  a2 s .  co m*/
    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);
    solrQuery.setStart(start);/*from  www.  ja  v a2 s  .  c o m*/
    solrQuery.setRows(length);
    solrQuery.setFacet(true);
    solrQuery.setFacetMinCount(1);
    solrQuery.addFacetField(facetField);
    if (filterQuery != "") {
        solrQuery.addFilterQuery(filterQuery);
    }

    return sangerImagesCore.query(solrQuery);

}