Example usage for org.apache.solr.client.solrj SolrClient query

List of usage examples for org.apache.solr.client.solrj SolrClient query

Introduction

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

Prototype

public QueryResponse query(SolrParams params) throws SolrServerException, IOException 

Source Link

Document

Performs a query to the Solr server

Usage

From source file:at.kc.tugraz.ss.service.solr.impl.fct.SSSolrFct.java

License:Apache License

public static SolrDocumentList query(final SolrClient solrQuerier, final SSSolrQueryPars queryPars)
        throws Exception {

    final SolrQuery solrQuery = new SolrQuery();

    solrQuery.setQuery(queryPars.query);
    solrQuery.setRows(queryPars.numRows);

    return solrQuerier.query(solrQuery).getResults();
}

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

License:Apache License

@Override
public long count(final SolrDataQuery query) {
    Assert.notNull(query, "Query must not be 'null'.");

    return execute(new SolrCallback<Long>() {

        @Override//from ww  w.  j  a v  a2s  . c  o m
        public Long doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
            SolrQuery solrQuery = queryParsers.getForClass(query.getClass()).constructSolrQuery(query);
            solrQuery.setStart(0);
            solrQuery.setRows(0);

            return solrClient.query(solrQuery).getResults().getNumFound();
        }
    });
}

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

License:Apache License

final QueryResponse executeSolrQuery(final SolrParams solrParams) {
    return execute(new SolrCallback<QueryResponse>() {
        @Override//from   ww w .  j  a v a 2  s.  co  m
        public QueryResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
            return solrClient.query(solrParams);
        }
    });
}

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

License:Apache License

@Test
public void testTokenizerInSolr() throws SolrServerException, IOException {
    SolrClient server = rule.getClient();
    ModifiableSolrParams params = new ModifiableSolrParams();

    // ** Let's index a document into our embedded server

    SolrInputDocument newDoc = new SolrInputDocument();
    newDoc.addField("host", "Test Document 1");
    newDoc.addField("name", "doc-1");
    newDoc.addField("type", "Hello world!");
    newDoc.addField("start", new Date().getTime());
    newDoc.addField("end", new Date().getTime() + 1000);
    server.add(newDoc);/*from  ww w .j  a va 2s.c o m*/
    server.commit();

    // ** And now let's query for it

    params.set("q", "name:doc-1");
    QueryResponse qResp = server.query(params);

    SolrDocumentList docList = qResp.getResults();
    assertTrue(docList.getNumFound() == 1);
    SolrDocument doc = docList.get(0);
    assertTrue(doc.getFirstValue("host").equals("Test Document 1"));
}

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

License:Apache License

@Override
public QueryResponse executeQuery(String q, String fq, String qt, boolean highlight, String facetFields,
        String sort, String sortOrder, Integer rows, Integer start, String otherParams) throws QueryException {
    SolrClient client = SolrClientFactory.getSolrClientForQuery();
    SolrQuery query = this.createQuery(q, fq, qt, highlight, facetFields, sort, sortOrder, rows, start,
            otherParams);//  w ww.java2s .c o m
    QueryResponse response = null;
    try {
        response = client.query(query);
    } catch (SolrServerException e) {
        throw new QueryException(e);
    } catch (IOException e) {
        throw new QueryException(e);
    }
    return response;
}

From source file:com.indoqa.solr.spring.client.SolrClientFactoryTest.java

License:Apache License

public void createCloudSolrClient() throws SolrServerException, IOException {
    SolrClientFactory solrClientFactory = new SolrClientFactory();
    solrClientFactory.setUrl("cloud://localhost:12181,localhost:12182?collection=deep-storage-1.10");
    solrClientFactory.initialize();/*  ww w  .j  a v a2s .c  o  m*/

    SolrClient solrClient = solrClientFactory.getObject();

    QueryResponse response = solrClient.query(new SolrQuery("*:*"));
    assertNotNull(response);
    assertEquals(0, response.getResults().getNumFound());

    solrClientFactory.destroy();
}

From source file:com.indoqa.solr.spring.client.SolrClientFactoryTest.java

License:Apache License

public void createEmbeddedSolrClientClasspath() throws SolrServerException, IOException {
    SolrClientFactory solrClientFactory = new SolrClientFactory();
    solrClientFactory.setUrl("file://./target/solr/classpath-test-core");
    solrClientFactory.setEmbeddedSolrConfigurationPath("solr/classpath");
    solrClientFactory.initialize();/*from w w w . j a  v a  2 s .c  o m*/

    SolrClient solrClient = solrClientFactory.getObject();

    QueryResponse response = solrClient.query(new SolrQuery("*:*"));
    assertNotNull(response);
    assertEquals(0, response.getResults().getNumFound());

    solrClientFactory.destroy();
}

From source file:com.indoqa.solr.spring.client.SolrClientFactoryTest.java

License:Apache License

@Test
public void createEmbeddedSolrClientFile() throws SolrServerException, IOException {
    SolrClientFactory solrClientFactory = new SolrClientFactory();
    solrClientFactory.setUrl("file://./target/solr/file-test-core");
    solrClientFactory.setEmbeddedSolrConfigurationPath("./src/test/resources/solr/file");
    solrClientFactory.initialize();//from ww w.  j a v a2s  .c  o m

    SolrClient solrClient = solrClientFactory.getObject();

    QueryResponse response = solrClient.query(new SolrQuery("*:*"));
    assertNotNull(response);
    assertEquals(0, response.getResults().getNumFound());

    solrClientFactory.destroy();
}

From source file:com.indoqa.solr.spring.client.SolrClientFactoryTest.java

License:Apache License

public void createHttpSolrClient() throws SolrServerException, IOException {
    SolrClientFactory solrClientFactory = new SolrClientFactory();
    solrClientFactory.setUrl("http://localhost:18983/test-core");
    solrClientFactory.initialize();/*from   w  ww .  jav a2s.c  o  m*/

    SolrClient solrClient = solrClientFactory.getObject();

    QueryResponse response = solrClient.query(new SolrQuery("*:*"));
    assertNotNull(response);
    assertEquals(0, response.getResults().getNumFound());

    solrClientFactory.destroy();
}

From source file:de.qaware.chronix.solr.client.stream.SolrStreamingService.java

License:Apache License

private void initStreamingService(SolrQuery query, SolrClient connection) {
    SolrQuery solrQuery = query.getCopy();
    solrQuery.setRows(0);/*  w  w w.  j  av a  2 s  . c o  m*/
    //we do not need any data from the server expect the total number of found documents
    solrQuery.setFields("");

    try {
        QueryResponse response = connection.query(solrQuery);
        nrOfAvailableTimeSeries = response.getResults().getNumFound();
        queryStart = (long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_START_LONG);
        queryEnd = (long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_END_LONG);

    } catch (SolrServerException | IOException e) {
        LOGGER.error("SolrServerException occurred while querying server.", e);
    }
}