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:com.frank.search.solr.core.DefaultQueryParser.java

License:Apache License

private void processGroupOptions(SolrQuery solrQuery, Query query) {

    GroupOptions groupOptions = query.getGroupOptions();

    if (groupOptions == null || (CollectionUtils.isEmpty(groupOptions.getGroupByFields())
            && CollectionUtils.isEmpty(groupOptions.getGroupByFunctions())
            && CollectionUtils.isEmpty(groupOptions.getGroupByQueries()))) {
        return;/*from w w w .  ja  v  a  2 s  . co m*/
    }

    solrQuery.set(GroupParams.GROUP, true);
    solrQuery.set(GroupParams.GROUP_MAIN, groupOptions.isGroupMain());
    solrQuery.set(GroupParams.GROUP_FORMAT, "grouped");

    if (!CollectionUtils.isEmpty(groupOptions.getGroupByFields())) {
        for (Field field : groupOptions.getGroupByFields()) {
            solrQuery.add(GroupParams.GROUP_FIELD, field.getName());
        }
    }

    if (!CollectionUtils.isEmpty(groupOptions.getGroupByFunctions())) {
        for (Function function : groupOptions.getGroupByFunctions()) {
            String functionFragment = createFunctionFragment(function, 0);
            setObjectNameOnGroupQuery(query, function, functionFragment);
            solrQuery.add(GroupParams.GROUP_FUNC, functionFragment);
        }
    }

    if (!CollectionUtils.isEmpty(groupOptions.getGroupByQueries())) {
        for (Query groupQuery : groupOptions.getGroupByQueries()) {
            String queryFragment = getQueryString(groupQuery);
            setObjectNameOnGroupQuery(query, groupQuery, queryFragment);
            solrQuery.add(GroupParams.GROUP_QUERY, queryFragment);
        }
    }

    if (groupOptions.getSort() != null) {

        for (Order order : groupOptions.getSort()) {
            solrQuery.add(GroupParams.GROUP_SORT,
                    order.getProperty().trim() + " " + (order.isAscending() ? ORDER.asc : ORDER.desc));
        }
    }

    if (groupOptions.getCachePercent() > 0) {
        solrQuery.add(GroupParams.GROUP_CACHE_PERCENTAGE, String.valueOf(groupOptions.getCachePercent()));
    }

    if (groupOptions.getLimit() != null && groupOptions.getLimit() >= 0) {
        solrQuery.set(GroupParams.GROUP_LIMIT, groupOptions.getLimit());
    }

    if (groupOptions.getOffset() != null && groupOptions.getOffset() >= 0) {
        solrQuery.set(GroupParams.GROUP_OFFSET, groupOptions.getOffset());
    }

    solrQuery.set(GroupParams.GROUP_TOTAL_COUNT, groupOptions.isTotalCount());
    solrQuery.set(GroupParams.GROUP_FACET, groupOptions.isGroupFacets());
    solrQuery.set(GroupParams.GROUP_TRUNCATE, groupOptions.isTruncateFacets());
}

From source file:com.frank.search.solr.core.DefaultQueryParser.java

License:Apache License

private boolean enableFaceting(SolrQuery solrQuery, FacetQuery query) {
    FacetOptions facetOptions = query.getFacetOptions();
    if (facetOptions == null || !facetOptions.hasFacets()) {
        return false;
    }//  w w  w . ja  v a  2 s . c o  m
    solrQuery.setFacet(true);
    solrQuery.setFacetMinCount(facetOptions.getFacetMinCount());
    solrQuery.setFacetLimit(facetOptions.getPageable().getPageSize());
    if (facetOptions.getPageable().getPageNumber() > 0) {
        int offset = Math.max(0, facetOptions.getPageable().getOffset());
        solrQuery.set(FacetParams.FACET_OFFSET, offset);
    }
    if (FacetOptions.FacetSort.INDEX.equals(facetOptions.getFacetSort())) {
        solrQuery.setFacetSort(FacetParams.FACET_SORT_INDEX);
    }
    return true;
}

From source file:com.frank.search.solr.core.query.result.DelegatingCursor.java

License:Apache License

private void load(String cursorMark) {

    SolrQuery query = referenceQuery.getCopy();
    query.set(CursorMarkParams.CURSOR_MARK_PARAM, this.getCursorMark());

    PartialResult<T> result = doLoad(query);
    process(result);// w  ww.  j  a va 2 s.c  om
}

From source file:com.frank.search.solr.core.QueryParserBase.java

License:Apache License

/**
 * Set {@code q.op} parameter for/*from w w w.  j  a v  a2  s . com*/
 * {@link org.apache.solr.client.solrj.SolrQuery}
 *
 * @param solrQuery
 * @param defaultOperator
 */
protected void appendDefaultOperator(SolrQuery solrQuery, Operator defaultOperator) {
    if (defaultOperator != null && !Operator.NONE.equals(defaultOperator)) {
        solrQuery.set("q.op", defaultOperator.asQueryStringRepresentation());
    }
}

From source file:com.frank.search.solr.core.QueryParserBase.java

License:Apache License

/**
 * Set {@code defType} for {@link org.apache.solr.client.solrj.SolrQuery}
 *
 * @param solrQuery/* w  ww . j  a v a2s.c o m*/
 * @param defType
 */
protected void appendDefType(SolrQuery solrQuery, String defType) {
    if (StringUtils.isNotBlank(defType)) {
        solrQuery.set("defType", defType);
    }
}

From source file:com.hurence.logisland.service.solr.api.SolrClientService.java

License:Apache License

@Override
public void copyCollection(String reindexScrollTimeout, String src, String dst)
        throws DatastoreClientServiceException {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setRows(1000);//from   w w w.j a v a  2 s  .  co m
    solrQuery.setQuery("*:*");
    solrQuery.addSort("id", SolrQuery.ORDER.asc); // Pay attention to this line
    String cursorMark = CursorMarkParams.CURSOR_MARK_START;
    boolean done = false;
    QueryResponse response;
    try {
        do {
            solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
            response = getClient().query(src, solrQuery);
            List<SolrInputDocument> documents = new ArrayList<>();
            for (SolrDocument document : response.getResults()) {
                SolrInputDocument inputDocument = getConverter().toSolrInputDocument(document);
                inputDocument.removeField("_version_");
                documents.add(inputDocument);
            }

            getClient().add(dst, documents);

        } while (cursorMark.equals(response.getNextCursorMark()));

        getClient().commit(dst);
    } catch (Exception e) {
        throw new DatastoreClientServiceException(e);
    }
}

From source file:com.ifactory.press.db.solr.processor.UpdateDocValuesTest.java

License:Apache License

@Test
/**//  www.  jav a2s  .  c o  m
 * When we insert a document without having set up docvalues
 */
public void testZeroDefault() throws Exception {
    insertTestDocuments(10, true);
    SolrQuery query = new SolrQuery("*:*");
    String dvFieldFunction = String.format("field(%s)", WEIGHT_DV);
    query.set("fl", dvFieldFunction);
    QueryResponse resp = solr.query(query);
    SolrDocumentList docs = resp.getResults();
    assertEquals(0, docs.get(0).getFirstValue(dvFieldFunction));
}

From source file:com.lanacion.adminsiteln.config.SolrConnection.java

public int countDocuments(String UserQuery) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    if (UserQuery.length() > 0) {
        query.setQuery(UserQuery);/*  w  ww . j  a  va2s.c o  m*/
    } else {
        query.setQuery("*:*");
    }
    //query.addFilterQuery("cat:electronics","store:amazon.com");
    query.setFields("titulo", "cuerpo");
    query.setStart(0);
    query.setRows(10000);
    query.set("defType", "edismax");

    QueryResponse response = solrCore.query(query);
    SolrDocumentList results = response.getResults();

    return results.size();
}

From source file:com.sindicetech.siren.solr.qparser.TestConciseTreeQParser.java

License:Open Source License

@Test
public void testSimpleConciseTreeQuery() throws IOException, SolrServerException, QueryNodeException {
    this.addJsonString("1", "concise", "{ \"aaa\" :  { \"bbb\" : \"ccc\" } }");

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();
    query.setQuery(b.newTwig("aaa").with(b.newNode("ccc").setAttribute("bbb")).toString());
    query.setRequestHandler("tree");
    query.set("qf", "concise");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);//from   w  w w.  ja  v a2 s . c  o  m
}

From source file:com.sindicetech.siren.solr.qparser.TestConciseTreeQParser.java

License:Open Source License

/**
 * Checks that a keyword query that matches no document (the term down is in the stop list)
 * does not throw exception and returns an empty result set.
 *
 * See #73./*from  w  w w  .ja  v  a  2 s  .c o  m*/
 */
@Test
public void testKeywordQueryMatchingNoDoc() throws IOException, SolrServerException, QueryNodeException {
    this.addJsonString("1", "concise", "{ \"aaa\" :  { \"bbb\" : \"ccc\" } }");

    SolrQuery query = new SolrQuery();
    query.setQuery("{\"node\":{\"query\":\"down\"}}");
    query.setRequestHandler("tree");
    query.set("qf", "concise");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(0, results.length);
}