List of usage examples for org.apache.solr.client.solrj SolrQuery setQuery
public SolrQuery setQuery(String query)
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);/* w w w.j a va2s . 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./*from w w w . jav 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);/* w w w .j ava2 s .c o m*/ }
From source file:com.sindicetech.siren.solr.qparser.TestConciseTreeQParser.java
License:Open Source License
@Test public void testSpanConciseTreeQuery() throws IOException, SolrServerException, QueryNodeException { this.addJsonString("1", "concise", "{ \"aaa\" : { \"bbb\" : \"ccc\", \"ddd\" : \"eee\" } }"); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); final TwigQuery twig = b.newTwig("aaa").with(b.newBoolean().with(b.newNode("ccc").setAttribute("bbb")) .with(b.newNode("eee").setAttribute("ddd")).setInOrder(false)); query.setQuery(twig.toString()); query.setRequestHandler("tree"); query.set("qf", "concise"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);// w ww. j av a 2 s.c o m }
From source file:com.sindicetech.siren.solr.qparser.TestConciseTreeQParser.java
License:Open Source License
/** * Issue #66: The query parser applies lowercase the expanded terms */// w ww. jav a2s .co m @Test public void testPrefixQueryConciseTreeQuery() throws IOException, SolrServerException, QueryNodeException { this.addJsonString("1", "concise-keyword", "{ \"rdfs:label\" : \"COM_GRANAGLIONE\" }"); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); query.setQuery(b.newNode("COM_*").setAttribute("rdfs:label").toString()); query.setRequestHandler("tree"); query.set("qf", "concise-keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
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 . jav a2 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 + " }"); }/*w w w . ja v a 2 s . 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\"" + "} }"); }//from w w w . ja v a 2 s. co m 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 ww. j a va2 s. co m*/ }
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);/*from w ww . j a v a 2s .c o m*/ }