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

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

Introduction

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

Prototype

public SolrQuery() 

Source Link

Usage

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

License:Apache License

public Collection<Record> query(String queryString, String collectionName) {
    try {//from w  ww.j a v  a  2  s . c o m
        String uniqueKey = getUniqueKey(collectionName);
        SolrQuery query = new SolrQuery();
        query.setQuery(queryString);

        QueryResponse response = getClient().query(collectionName, query);

        Collection<Record> results = new ArrayList<>();
        response.getResults().forEach(document -> {
            results.add(getConverter().toRecord(document, uniqueKey));
        });

    } catch (SolrServerException | IOException e) {
        logger.error(e.toString());
        throw new DatastoreClientServiceException(e);
    }

    return null;
}

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

License:Apache License

public long queryCount(String queryString, String collectionName) {
    try {/*  w  w  w  .j a  va 2 s  . c  o  m*/
        SolrQuery query = new SolrQuery();
        query.setQuery(queryString);

        QueryResponse response = getClient().query(collectionName, query);

        return response.getResults().getNumFound();

    } catch (SolrServerException | IOException e) {
        logger.error(e.toString());
        throw new DatastoreClientServiceException(e);
    }
}

From source file:com.hurence.logisland.service.solr.Solr_6_4_2_ChronixClientService.java

License:Apache License

@Override
public Collection<Record> query(String queryString) {
    try {//from   w w  w .j a  va 2 s  .c o m
        SolrQuery query = new SolrQuery();
        query.setQuery(queryString);

        QueryResponse response = solr.query(query);

        //response.getResults().forEach(doc -> doc.);

    } catch (SolrServerException | IOException e) {
        logger.error(e.toString());
        throw new DatastoreClientServiceException(e);
    }

    return null;
}

From source file:com.hurence.logisland.service.solr.Solr_6_4_2_ChronixClientService.java

License:Apache License

@Override
public long queryCount(String queryString) {
    try {// w w  w  . j a v a 2s  .c o  m
        SolrQuery query = new SolrQuery();
        query.setQuery(queryString);

        QueryResponse response = solr.query(query);

        return response.getResults().getNumFound();

    } catch (SolrServerException | IOException e) {
        logger.error(e.toString());
        throw new DatastoreClientServiceException(e);
    }
}

From source file:com.idealista.solrmeter.model.service.impl.QueryServiceSolrJImpl.java

License:Apache License

protected SolrQuery createQuery(String q, String fq, String qt, boolean highlight, String facetFields,
        String sort, String sortOrder, Integer rows, Integer start, String otherParams) throws QueryException {
    SolrQuery query = new SolrQuery();
    if (q != null) {
        query.setQuery(q);/*w w  w.ja  v a  2  s.  c o m*/
    }
    if (fq != null) {
        List<String> filterQueries = this.getFilterQueries(fq);
        for (String filterQuery : filterQueries) {
            query.addFilterQuery(filterQuery);
        }
    }

    query.setHighlight(highlight);
    if (facetFields == null || "".equals(facetFields)) {
        query.setFacet(false);
    } else {
        query.setFacet(true);
        List<String> facets = this.getFacets(facetFields);
        for (String facet : facets) {
            query.addFacetField(facet);
        }
    }
    if (sort != null && !"".equals(sort)) {
        query.setSort(sort, ORDER.valueOf(sortOrder));
    }
    if (rows != null && rows < 0) {
        throw new QueryException("Rows can't be less than 0");
    } else if (rows != null) {
        query.setRows(rows);
    }
    if (start != null && start < 0) {
        throw new QueryException("Rows can't be less than 0");
    } else if (start != null) {
        query.setStart(start);
    }

    if (otherParams != null) {
        List<String> params = this.getOtherParams(otherParams);
        for (String param : params) {
            query.add(getParamName(param), getParamValue(param));
        }
    }
    return query;
}

From source file:com.idealista.solrmeter.statistic.QueryLogStatisticTestCase.java

License:Apache License

private QueryException createQueryException() {
    QueryException queryException = new QueryException();
    SolrQuery query = new SolrQuery();
    query.setQuery("test");
    query.setFilterQueries("field=value");
    query.addFacetQuery("filterQuery=value");
    queryException.setQuery(query);/*from  ww w . j a v  a2s. com*/
    return queryException;
}

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

License:Apache License

private List<TermsResponse.Term> getTerms(String field) throws SolrServerException {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setParam(CommonParams.QT, "/terms");
    solrQuery.setParam(TermsParams.TERMS, true);
    solrQuery.setParam(TermsParams.TERMS_LIMIT, "100");
    solrQuery.setParam(TermsParams.TERMS_FIELD, field);
    QueryResponse resp = solr.query(solrQuery);
    return resp.getTermsResponse().getTermMap().get(field);
}

From source file:com.ir.qa.QueryProcessor.SpellCorrector.java

License:Apache License

public String topSuggestion(String spelling) throws SolrServerException {
    HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
    SolrQuery query = new SolrQuery();
    query.setFields("name");
    query.setRows(50);/*from   w  w w . j  av a 2  s .  c  o  m*/
    query.setQuery("wordNGram:" + spelling); //<co id="co.dym.field"/>
    QueryResponse response = solr.query(query);
    SolrDocumentList results = response.getResults();
    Levenshtein levenshtein = new Levenshtein();
    float maxDistance = 0;
    float distance = 0;
    String suggestion = null;
    List<String> nameList = new ArrayList<String>();

    for (int i = 0; i < results.size(); i++) {
        // System.out.println(results.get(i));
        SolrDocument doc = results.get(i);

        nameList = (List<String>) doc.getFieldValue("name");
        for (String name_suggestions : nameList) {
            distance = levenshtein.getSimilarity(name_suggestions, spelling);
            System.out.println(name_suggestions);

            System.out.println(distance);

            if (distance > maxDistance) {
                maxDistance = distance;
                suggestion = name_suggestions;
            }
        }

        if (maxDistance > threshold) { //<co id="co.dym.threshold"/>

            return suggestion;
        }
    }

    return null;
}

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);//from  w ww  .ja  v  a 2 s  .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.liferay.portal.search.solr.internal.SolrIndexSearcher.java

License:Open Source License

protected QueryResponse doSearch(SearchContext searchContext, Query query, int start, int end, boolean count)
        throws Exception {

    QueryConfig queryConfig = query.getQueryConfig();

    SolrQuery solrQuery = new SolrQuery();

    if (!count) {
        addFacets(solrQuery, searchContext);
        addHighlights(solrQuery, queryConfig);
        addPagination(solrQuery, start, end);
        addSelectedFields(solrQuery, queryConfig);
        addSort(solrQuery, searchContext.getSorts());

        solrQuery.setIncludeScore(queryConfig.isScoreEnabled());
    } else {/*from w  ww . j ava 2 s. c om*/
        solrQuery.setRows(0);
    }

    String queryString = translateQuery(query, searchContext);

    solrQuery.setQuery(queryString);

    String filterQuery = _filterTranslator.translate(query.getPreBooleanFilter(), searchContext);

    solrQuery.setFilterQueries(filterQuery);

    QueryResponse queryResponse = executeSearchRequest(solrQuery);

    if (_log.isInfoEnabled()) {
        _log.info("The search engine processed " + solrQuery.getQuery() + " in "
                + queryResponse.getElapsedTime() + " ms");
    }

    return queryResponse;
}