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

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

Introduction

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

Prototype

public SolrQuery setRequestHandler(String qt) 

Source Link

Document

The Request Handler to use (see the solrconfig.xml), which is stored in the "qt" parameter.

Usage

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

License:Open Source License

@Test
public void testDebugConciseTreeQuery() throws IOException, SolrServerException, QueryNodeException {
    this.addJsonString("1", "concise",
            "{\"@graph\":[{\"@id\":\"http://dbpedia/Person/1\",\"http://www.w3.org/2000/01/rdf-schema#label\":\"Alfred Hitchkoc\",\"http://www.w3.org/2000/01/rdf-schema#seeAlso\":{\"@id\":\"http://dbpedia/Person/2\",\"http://www.w3.org/2000/01/rdf-schema#label\":\"Brad Pitt\"}},{\"@id\":\"http://dbpedia/Person/2\",\"http://www.w3.org/2000/01/rdf-schema#label\":\"Brad Pitt\"}]}");
    this.addJsonString("2", "concise",
            "{\"@graph\":[{\"http://www.w3.org/2000/01/rdf-schema#label\":\"Alfred Hitchkoc\",\"@id\":\"http://dbpedia/Person/1\",\"http://www.w3.org/2000/01/rdf-schema#seeAlso\":{\"@id\":\"http://dbpedia/Person/2\",\"http://www.w3.org/2000/01/rdf-schema#label\":\"Brad Pitt\"}},{\"@id\":\"http://dbpedia/Person/2\",\"http://www.w3.org/2000/01/rdf-schema#label\":\"Brad Pitt\"}]}");

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();

    //    String q = b.newTwig()
    //                .with(
    //      b.newTwig("http://www.w3.org/2000/01/rdf-schema#seeAlso")
    //       .with(b.newNode("'http://dbpedia/Person/2'").setAttribute("@id"))
    //                )
    //                .with(
    //      b.newNode("Alfred Hitchkoc").setAttribute("http://www.w3.org/2000/01/rdf-schema#label")
    //                ).toString();

    String q = b.newTwig()/*from  w w w  . j a  v  a 2  s .c o  m*/
            .with(b.newTwig("http://www.w3.org/2000/01/rdf-schema#seeAlso")
                    .with(b.newNode("'http://dbpedia/Person/2'").setAttribute("@id")), 1)
            .with(b.newNode("Alfred Hitchkoc").setAttribute("http://www.w3.org/2000/01/rdf-schema#label"), 1)
            .toString();

    query.setQuery(q);
    query.setRequestHandler("tree");
    query.set("qf", "concise");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(2, results.length);
}

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

License:Open Source License

@Test
public void testTrieDatatypeQuery() throws IOException, SolrServerException {
    for (int i = 0; i < 1000; i++) {
        this.addJsonStringWoCommit("id" + i, "{ \"numeric\" : " + i + " }");
    }/*ww w .ja  v a 2s  .  c  o m*/

    this.commit();

    final SolrQuery query = new SolrQuery();
    // by default, the json tokenizer index numeric value as long
    query.setQuery("numeric : xsd:long([501 TO *])");
    query.setRequestHandler("keyword");
    assertEquals(499, this.search(query).getNumFound());
}

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

License:Open Source License

@Test
public void testTrieDateDatatypeQuery() throws IOException, SolrServerException {
    for (int i = 0; i < 1000; i++) {
        this.addJsonStringWoCommit("id" + i,
                "{ \"date\" : { " + "\"_value_\" : \"" + (1000 + i) + "-12-31T00:00:00Z\", "
                        + "\"_datatype_\" : \"http://www.w3.org/2001/XMLSchema#date\"" + "} }");
    }//w  w  w.j  av a2  s.c  om

    this.commit();

    final SolrQuery query = new SolrQuery();
    // by default, the json tokenizer index numeric value as long
    query.setQuery("date : xsd:date([1995-12-31T00:00:00Z TO 1995-12-31T00:00:00Z+5YEARS])");
    query.setRequestHandler("keyword");
    assertEquals(5, this.search(query).getNumFound());
}

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

License:Open Source License

@Test
public void testURIDatatypeQuery() throws SolrServerException, IOException, QueryNodeException {
    this.addJsonString("1", "{ \"uri\" : { " + "\"_value_\" : \"http://xmlns.com/foaf/0.1/Person\", "
            + "\"_datatype_\" : \"uri\" " + "} }");

    final SolrQuery query = new SolrQuery();
    final QueryBuilder b = new QueryBuilder();
    query.setQuery(b.newTwig("uri").with(b.newNode("uri('http://xmlns.com/foaf/0.1/Person')")).toString());
    query.setRequestHandler("tree");
    final String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);//  w w w .  j a  va2 s  .c  om
}

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

License:Open Source License

@Test
public void testBooleanDatatypeQuery() throws SolrServerException, IOException, QueryNodeException {
    this.addJsonString("1", "{ \"boolean\" : true }");

    final SolrQuery query = new SolrQuery();
    query.setQuery("true");
    query.setRequestHandler("keyword");
    final String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);// w ww .  j  a  va2  s  .c  om
}

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

License:Open Source License

@Test
public void testDoubleQuery() throws SolrServerException, IOException, QueryNodeException {
    this.addJsonString("1",
            "{\"@id\":\"http://therealbanff.com/event/112\",\"costValue\":{\"_datatype_\":\"http://www.w3.org/2001/XMLSchema#double\",\"_value_\":\"0.00\"}}");

    final SolrQuery query = new SolrQuery();
    final QueryBuilder b = new QueryBuilder();
    query.setQuery(b.newNode("xsd:double([-1.0 TO 1.0])").toString());
    query.setRequestHandler("tree");
    final String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);/*from   w w w  .  java2  s. c  o  m*/
}

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

License:Open Source License

@Test
public void testDefaultOperator() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb ccc\" }");
    this.addJsonString("2", "{ \"aaa\" : \"bbb\" }");
    this.addJsonString("3", "{ \"aaa\" : \"ccc\" }");

    SolrQuery query = new SolrQuery();
    query.setQuery("bbb ccc");
    query.setRequestHandler("keyword");
    String[] results = this.search(query, URL_FIELD);
    // Default Operator = AND : Only one document should match
    assertEquals(1, results.length);//from   w ww. j a va 2s  .c  o  m

    query = new SolrQuery();
    query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }");
    query.setRequestHandler("tree");
    results = this.search(query, URL_FIELD);
    // Default Operator = AND : Only one document should match
    assertEquals(1, results.length);
}

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

License:Open Source License

@Test
public void testQOpParameter() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb ccc\" }");
    this.addJsonString("2", "{ \"aaa\" : \"bbb\" }");
    this.addJsonString("3", "{ \"aaa\" : \"ccc\" }");

    SolrQuery query = new SolrQuery();
    query.setQuery("bbb ccc");
    query.setRequestHandler("keyword");
    query.set(QueryParsing.OP, "OR");
    String[] results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);/*from w  w  w  . j  av a 2s.c o  m*/

    query = new SolrQuery();
    query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }");
    query.setRequestHandler("tree");
    query.set(QueryParsing.OP, "OR");
    results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);
}

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

License:Open Source License

public void testNullJsonQuery() throws SolrServerException, IOException {
    final SolrQuery query = new SolrQuery();
    query.setRequestHandler("tree");
    this.search(query, ID_FIELD);
}

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

License:Open Source License

@Test(expected = SolrException.class)
public void testEmptyJsonQuery() throws SolrServerException, IOException {
    final SolrQuery query = new SolrQuery();
    query.setQuery(" ");
    query.setRequestHandler("tree");
    this.search(query, ID_FIELD);
}