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.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  av a 2s  . com
@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  ww  w.j a v  a  2  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);
}

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

License:Open Source License

/**
 * Check that nested array are properly flattened.
 *///from   w  ww  .j  av a2  s  .c  om
@Test
public void testNestedArray() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  [\"ccc\", [ \"ddd\", [\"eee\"] ] ] }";

    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:ddd");
    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 nested objects are properly flattened.
 *///from  w  w w. j a  va  2s.  c o  m
@Test
public void testNestedObject() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  { \"ccc\" : { \"ddd\" : \"eee\" }, \"fff\" : \"ggg\" } }";

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

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

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb.fff:ggg");
    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 nested objects in a mixed array are properly flattened.
 *//*  ww  w  . ja  va  2s  .  c o m*/
@Test
public void testNestedObjectInArray() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  [ \"ccc\", { \"ddd\" : \"eee\" }, \"ggg\" ] }";

    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.ddd:eee");
    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 special SIREn's object for datatype is properly flattened.
 *//*  w  w  w.j a  va 2  s  .co m*/
@Test
public void testDatatypeObject() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  { \"_datatype_\" : \"uri\", \"_value_\" : \"ccc\" } }";

    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);
}

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

License:Open Source License

/**
 * Check that the nested query and the main query are intersected, i.e., that each one is assigned a MUST operator.
 * See issue #60.//from w ww .j  a va2 s.c  o m
 */
@Test
public void testNestedQuery() throws IOException, SolrServerException, QueryNodeException {
    String input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM765\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }";
    this.sendUpdateRequest(input);
    input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM556\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }";
    this.sendUpdateRequest(input);
    input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM779\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }";
    this.sendUpdateRequest(input);

    this.commit();

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();
    query.setQuery(b.newNode("CM765").setAttribute("ChargeDeviceRef").toString());
    query.setParam("nested", "ChargeDeviceLocation.Address.PostTown:Peterborough");
    query.setRequestHandler("tree");

    long found = this.search(query).getNumFound();
    assertEquals(1, found);
}

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

License:Open Source License

@Test
public void testSimpleConciseTreeQuery() throws IOException, SolrServerException, QueryNodeException {
    this.addJsonString("1", "concise", "{ \"aaa\" :  { \"bbb\" : \"ccc\" } }");

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();
    query.setQuery(b.newTwig("aaa").with(b.newNode("ccc").setAttribute("bbb")).toString());
    query.setRequestHandler("tree");
    query.set("qf", "concise");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);//from  w  ww  .  j av a 2  s.  c  o m
}

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

License:Open Source License

/**
 * Checks that a keyword query that matches no document (the term down is in the stop list)
 * does not throw exception and returns an empty result set.
 *
 * See #73./*  w w w  .j a v  a2 s  .  c o  m*/
 */
@Test
public void testKeywordQueryMatchingNoDoc() throws IOException, SolrServerException, QueryNodeException {
    this.addJsonString("1", "concise", "{ \"aaa\" :  { \"bbb\" : \"ccc\" } }");

    SolrQuery query = new SolrQuery();
    query.setQuery("{\"node\":{\"query\":\"down\"}}");
    query.setRequestHandler("tree");
    query.set("qf", "concise");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(0, results.length);
}

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

License:Open Source License

@Test
public void testConciseTreeAttributeWildcard() throws IOException, SolrServerException, QueryNodeException {
    this.addJsonString("1", "concise-attribute-wildcard", "{ \"aaa\" :  { \"bbb\" : \"ccc\" } }");

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();
    query.setQuery(b.newNode("ccc").toString());
    query.setRequestHandler("tree");
    query.set("qf", "concise-attribute-wildcard");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);//  ww  w  . ja va2 s.c o  m
}