List of usage examples for org.apache.solr.client.solrj SolrQuery SolrQuery
public SolrQuery()
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());/*from w w w.jav a2 s . c o m*/ query.setRequestHandler("tree"); query.set("qf", "concise"); 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
/** * Issue #66: The query parser applies lowercase the expanded terms *///w w w . j a va2 s .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()// ww 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 + " }"); }// www . ja v a 2 s. c om 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 . j av a 2 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 .ja v a 2s.c o 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 www . java 2 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 ww w . j a va2 s. co 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 . ja va 2 s. 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);// w w w .j ava 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); }