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:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java

License:Open Source License

private SolrQuery getLessThanOrEqualToQuery(String propertyName, AttributeFormat format, Number literal) {
    String mappedPropertyName = getMappedPropertyName(propertyName, format, true);

    SolrQuery query = new SolrQuery();
    query.setQuery(" " + mappedPropertyName + ":[ * TO " + literal.toString() + " ] ");

    return query;
}

From source file:ddf.catalog.cache.solr.impl.SolrFilterDelegate.java

License:Open Source License

private SolrQuery getLessThanQuery(String propertyName, AttributeFormat format, Number literal) {
    String mappedPropertyName = getMappedPropertyName(propertyName, format, true);

    SolrQuery query = new SolrQuery();
    query.setQuery(" " + mappedPropertyName + ":[ * TO " + literal.toString() + " } ");

    return query;
}

From source file:ddf.catalog.source.solr.DynamicSchemaResolver.java

License:Open Source License

/**
 * Adds the fields that are already in the server to the cache. This method should be called
 * once the SolrServer is up to ensure the cache is synchronized with the server.
 *
 * @param server//from  ww w .  j  a  v  a  2  s .com
 *            the SolrServer we are working with
 */
public void addFieldsFromServer(SolrServer server) {
    if (server == null) {
        LOGGER.warn("Server is null, could not add fields to cache.");
        return;
    }

    SolrQuery query = new SolrQuery();

    // numterms=0 means retrieve everything (regular or dynamic fields)
    query.add("numterms", "0");

    /*
     * Adding this request handler allows us to query the schema dynamically. The name of the
     * request handler is provided by the schema.xml. If the name is changed in the schema.xml,
     * then this value must be changed as well.
     */
    query.setRequestHandler("/admin/luke");

    try {
        QueryResponse response = server.query(query);
        for (Entry<String, ?> e : ((SimpleOrderedMap<?>) (response.getResponse().get(FIELDS_KEY)))) {
            fieldsCache.add(e.getKey());
        }
    } catch (SolrServerException | SolrException e) {
        LOGGER.warn("Could not update cache for field names.", e);
    }
}

From source file:ddf.catalog.source.solr.SolrMetacardClient.java

License:Open Source License

public List<Metacard> query(String queryString) throws UnsupportedQueryException {
    SolrQuery query = new SolrQuery();
    query.setQuery(queryString);/*from  www .j a v a 2  s .c  om*/
    try {
        QueryResponse solrResponse = server.query(query, SolrRequest.METHOD.POST);
        SolrDocumentList docs = solrResponse.getResults();

        List<Metacard> results = new ArrayList<>();
        for (SolrDocument doc : docs) {
            try {
                results.add(createMetacard(doc));
            } catch (MetacardCreationException e) {
                LOGGER.warn("Metacard creation exception creating result", e);
                throw new UnsupportedQueryException("Could not create metacard(s).");
            }
        }

        return results;
    } catch (SolrServerException e) {
        LOGGER.warn("Failure in Solr server query.", e);
        throw new UnsupportedQueryException("Could not complete solr query.");
    }

}

From source file:ddf.catalog.source.solr.SolrMetacardClientImpl.java

License:Open Source License

@Override
public List<Metacard> query(String queryString) throws UnsupportedQueryException {
    SolrQuery query = new SolrQuery();
    query.setQuery(queryString);/* w w w  .  j  a v  a2s.co m*/
    try {
        QueryResponse solrResponse = client.query(query, SolrRequest.METHOD.POST);
        SolrDocumentList docs = solrResponse.getResults();

        List<Metacard> results = new ArrayList<>();
        for (SolrDocument doc : docs) {
            try {
                results.add(createMetacard(doc));
            } catch (MetacardCreationException e) {
                throw new UnsupportedQueryException("Could not create metacard(s).", e);
            }
        }

        return results;
    } catch (SolrServerException | IOException e) {
        throw new UnsupportedQueryException("Could not complete solr query.", e);
    }

}

From source file:de.dlr.knowledgefinder.webapp.webservice.solr.query.AbstractSolrQueryFactory.java

License:Apache License

private SolrQuery createSolrQueryWithQueryString(String query) {
    SolrQuery solrQuery = new SolrQuery();

    String appendQuery = getAppendQuery().trim();
    String qValue = query;//w  w w.  j a v  a 2  s  . c  o  m
    if (appendQuery != "" && !appendQuery.equals(qValue)) {
        qValue = appendQuery + " AND " + qValue;
    }
    solrQuery.setQuery(qValue);
    solrQuery.addField(null);

    return solrQuery;
}

From source file:de.dlr.knowledgefinder.webapp.webservice.solr.query.AbstractSolrQueryFactoryTest.java

License:Apache License

@Before
public void setup() {
    factory = new SampleSolrQueryFactory();
    solrQuery = new SolrQuery();

    query = "id";
    filterQuery = new String[] { "popularity:[10 TO *]" };
    fields = new String[] { "title" };
    facetFields = new String[] { "id" };
    start = "1";//from  www  .j  a v  a2 s. c  o m
    rows = "10";
    sort = new String[] { "title desc" };
    highlightFields = new String[] { "title" };
    limit = "9";

    expectedContext.put("query", "*:* AND id");
    expectedContext.put("filterQuery", new String[] { "popularity:[10 TO *]" });
    expectedContext.put("fields", "title");
    expectedContext.put("facetFields", new String[] { "id" });
    expectedContext.put("start", 1);
    expectedContext.put("rows", 10);
    expectedContext.put("sort", Arrays.asList(new SortClause[] { new SortClause("title", ORDER.desc) }));
    expectedContext.put("highlightFields", new String[] { "title" });
    expectedContext.put("limit", 9);
}

From source file:de.fatalix.book.importer.SolrHandler.java

License:Open Source License

public static QueryResponse searchSolrIndex(SolrServer solr, String queryString, int rows, int startOffset)
        throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery(queryString);//from   w ww  . j  a va  2s .c o  m

    query.setRows(rows);
    query.setStart(startOffset);
    QueryResponse rsp = solr.query(query);
    return rsp;
}

From source file:de.fatalix.bookery.bl.solr.SolrHandler.java

License:Open Source License

public QueryResponse searchSolrIndex(String queryString, String fields, int rows, int startOffset)
        throws SolrServerException {
    SolrServer solr = null;/*from  w w  w .j a v a 2  s . c o  m*/
    try {
        solr = bookeryService.getSolrConnection();
    } catch (IOException ex) {
        throw new SolrServerException(ex.getMessage());
    }
    SolrQuery query = new SolrQuery();
    query.setQuery(queryString);
    query.setRows(rows);
    query.setStart(startOffset);

    query.setFields(fields);
    QueryResponse rsp = solr.query(query);
    return rsp;
}

From source file:de.fatalix.bookery.bl.solr.SolrHandler.java

License:Open Source License

public QueryResponse searchSolrIndexSorted(String queryString, String fields, int rows, int startOffset,
        String sortField) throws SolrServerException {
    SolrServer solr = null;//from w  w w.  j a  v  a2s  .c o  m
    try {
        solr = bookeryService.getSolrConnection();
    } catch (IOException ex) {
        throw new SolrServerException(ex.getMessage());
    }
    SolrQuery query = new SolrQuery();
    query.setQuery(queryString);
    query.setRows(rows);
    query.setStart(startOffset);
    query.setSort(sortField, SolrQuery.ORDER.desc);
    query.setFields(fields);
    QueryResponse rsp = solr.query(query);
    return rsp;
}