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.analysis.TestASCIIFoldingExpansionFilterFactory.java

License:Open Source License

/**
 * SRN-96/*  w  w  w. ja v  a 2s . c o  m*/
 */
@Test
public void testASCIIFoldingExpansion() throws IOException, SolrServerException {
    this.addJsonString("1", " { \"value\" : \"cafe\" } ");
    this.addJsonString("2", " { \"value\" : \"caf\" } ");
    SolrQuery query = new SolrQuery();
    query.setQuery("cafe");
    query.setRequestHandler("keyword");
    query.setIncludeScore(true);

    // should match the two documents, with same score
    QueryResponse response = getWrapper().getServer().query(query);
    SolrDocumentList docList = response.getResults();
    assertEquals(2, docList.getNumFound());
    float score1 = (Float) docList.get(0).getFieldValue("score");
    float score2 = (Float) docList.get(1).getFieldValue("score");
    Assert.assertTrue("Score should be identical", score1 == score2);

    // should match the two documents, but should assign different score
    // id2 should receive better score than id1
    query = new SolrQuery();
    query.setQuery("caf");
    query.setRequestHandler("keyword");
    query.setIncludeScore(true);

    response = getWrapper().getServer().query(query);
    docList = response.getResults();
    assertEquals(2, docList.getNumFound());
    if (docList.get(0).getFieldValue("url").equals("id1")) {
        score1 = (Float) docList.get(0).getFieldValue("score");
        score2 = (Float) docList.get(1).getFieldValue("score");
    } else {
        score2 = (Float) docList.get(0).getFieldValue("score");
        score1 = (Float) docList.get(1).getFieldValue("score");
    }
    Assert.assertTrue("id2 should get higher score than id1", score1 < score2);
}

From source file:com.sindicetech.siren.solr.facet.TestSirenFacetProcessorFactory.java

License:Open Source License

public void testCustomDatatypeField() throws Exception {
    String json = "{\"rating\": {\"_datatype_\": \"http://www.w3.org/2001/XMLSchema#double\", \"_value_\":\"5.4\"}}";

    IndexSchema schema = h.getCore().getLatestSchema();

    SolrInputDocument d = processAdd("generate-facets-processor", doc(f("id", "1"), f("json", json)));
    assertNotNull(d);/*from w  w  w.  java  2s. co m*/
    schema = h.getCore().getLatestSchema();
    assertNotNull(schema.getFieldOrNull("double.json.rating"));
    assertEquals("tdouble", schema.getFieldType("double.json.rating").getTypeName());
    assertTrue((5.4 - (double) d.getFieldValue("double.json.rating")) < 0.01);

    getWrapper().add(d); // add so that we can test facets by querying
    this.commit();

    SolrQuery q = new SolrQuery();
    q.setRequestHandler("keyword");
    q.setParam("nested", "{!lucene} *:*");
    q.setFacet(true);
    q.addFacetField("double.json.rating");
    QueryResponse r = getWrapper().getServer().query(q);
    // we know there is only one facet field with one value
    assertEquals(1, r.getFacetFields().get(0).getValues().get(0).getCount());

    json = "{\"rating\": {\"_datatype_\": \"http://www.w3.org/2001/XMLSchema#float\", \"_value_\":\"-8.4\"}}";
    schema = h.getCore().getLatestSchema();
    d = processAdd("generate-facets-processor", doc(f("id", "2"), f("json", json)));
    assertNotNull(d);
    schema = h.getCore().getLatestSchema();
    assertNotNull(schema.getFieldOrNull("double.json.rating"));
    assertEquals("tdouble", schema.getFieldType("double.json.rating").getTypeName());
    assertTrue((-8.4 + (double) d.getFieldValue("double.json.rating")) < 0.01);

    getWrapper().add(d); // add so that we can test facets by querying
    this.commit();

    r = getWrapper().getServer().query(q);

    // there is only one facet field with two different values each with a single count
    assertEquals(1, r.getFacetFields().get(0).getValues().get(0).getCount());
    assertEquals(1, r.getFacetFields().get(0).getValues().get(1).getCount());
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that a UUID is generated for JSON documents with no 'id' attribute.
 *///  w  w  w. j  av  a  2 s.  c  o m
@Test
public void testJsonWithNoId() throws IOException, SolrServerException {
    String input = "{ \"aaa\" :  \"bbb\" }";
    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} *:*");
    query.setRequestHandler("tree");
    query.setFields(IdFieldMapper.INPUT_FIELD);

    SolrDocumentList results = this.search(query);
    assertEquals(1, results.getNumFound());
    assertNotNull(results.get(0).getFieldValue(IdFieldMapper.INPUT_FIELD));
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that the value type of the id field do not have impact on the indexing.
 *//*from  w w w  .ja  va2s . c om*/
@Test
public void testJsonWithNumericId() throws IOException, SolrServerException {
    String input1 = "{ \"id\" : 1, \"aaa\" : null }";
    String input2 = "{ \"id\" : \"2\", \"aaa\" : null }";

    this.sendUpdateRequest(input1);
    this.sendUpdateRequest(input2);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} id:1");
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} id:2");
    query.setRequestHandler("tree");
    found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that the JSON document is correctly indexed in a SIREn's json field.
 *///  w w w . jav  a 2s  .c  o m
@Test
public void testJsonField() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" :  \"bbb\" }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();
    query.setQuery(b.newNode("bbb").setAttribute("aaa").toString());
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check if the field is stored as indicated by the fieldtype of the associated path-based mapper.
 *//*from  w ww . j  a v  a 2 s  .co m*/
@Test
public void testStoredField() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" :  \"bbb\" }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();
    query.setQuery(b.newNode("bbb").setAttribute("aaa").toString());
    query.setRequestHandler("tree");
    query.setFields("aaa");

    SolrDocumentList result = this.search(query);
    assertEquals(1, result.getNumFound());
    assertNotNull(result.get(0).getFieldValue("aaa"));
    assertTrue(result.get(0).getFieldValue("aaa") instanceof ArrayList);
    assertEquals("bbb", ((ArrayList) result.get(0).getFieldValue("aaa")).get(0));
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Test the optional mappers. The fields 'bbb' and 'ddd' are not defined, but the String and Boolean
 * value types are defined. They should be indexed.
 *//* www .j  a  v a 2  s. c om*/
@Test
public void testOptionalMapper() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  \"ccc\", \"ddd\" : false }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:ccc");
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} ddd:false");
    query.setRequestHandler("tree");
    found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Test the default mapper and the null field type. The field 'bbb' with an Integer value should
 * not match any mapper, and therefore be processed by the default mapper. The default mapper
 * is configured with the null field type which indicates to ignore the field. Therefore the
 * field 'bbb' should not be indexed and the search should throw an exception.
 *//*from  w ww.  j  a v a  2  s .com*/
@Test(expected = SolrException.class)
public void testDefaultNullMapper() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"bbb\" :  1 }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:1");
    query.setRequestHandler("tree");
    this.search(query);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Test the null field type. The path aaa.bbb is configured with the null field type which indicates to ignore the
 * field. Therefore the field 'aaa.bbb' should not be indexed and the search should throw an exception.
 *//* w w w .j  a v  a2s  .c om*/
@Test(expected = SolrException.class)
public void testNullMapper() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : { \"bbb\" : \"ccc\" } }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} aaa.bbb:ccc");
    query.setRequestHandler("tree");
    this.search(query);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Test mixed array. The String and Double type is defined, while the Integer is undefined. Integer will be ignored
 * and not indexed. The Double value will be indexed as a string.
 *//*from   www  . ja v a2 s . c  o m*/
@Test
public void testMixedTypeArray() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  [\"ccc\", 2, 3.1] }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:ccc");
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:2");
    query.setRequestHandler("tree");
    found = this.search(query).getNumFound();
    assertEquals(0, found);

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:3.1");
    query.setRequestHandler("tree");
    found = this.search(query).getNumFound();
    assertEquals(1, found);
}