List of usage examples for org.apache.solr.client.solrj SolrQuery setRequestHandler
public SolrQuery setRequestHandler(String qt)
From source file:org.sindice.siren.demo.ncpr.NCPRQuery.java
License:Apache License
/** * A query that shows how to build programatically a query for the JSON * query parser.//from www.j a v a 2 s . c o m */ private SolrQuery getJsonQuery() throws QueryNodeException { final SolrQuery query = new SolrQuery(); query.setRequestHandler("json"); // Use the SIREn core API for building query expressions. final NodeTermQuery uri = new NodeTermQuery(new Term("", "www.sourcelondon.net")); uri.setDatatype("uri"); final NodeTermQuery website = new NodeTermQuery(new Term("", "Website")); website.setDatatype("json:field"); final NodeTermQuery owner = new NodeTermQuery(new Term("", "DeviceOwner")); owner.setDatatype("json:field"); // Use the query builder to create twig query using the JSON query syntax. final QueryBuilder builder = new QueryBuilder(); final TwigQuery twq = builder.newTwig(owner.toString("json")) .with(builder.newTwig(website.toString("json")).with(builder.newNode(uri.toString("json"))), 2); query.setQuery(twq.toString()); return query; }
From source file:org.sindice.siren.solr.qparser.TestDatatypeQuery.java
License:Apache License
@Test public void testTrieDatatypeQuery() throws IOException, SolrServerException { for (int i = 0; i < 1000; i++) { this.addJsonStringWoCommit("id" + i, "{ \"numeric\" : " + i + " }"); }/*from w w w. ja va2 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)); }
From source file:org.sindice.siren.solr.qparser.TestDatatypeQuery.java
License:Apache 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 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)); }
From source file:org.sindice.siren.solr.qparser.TestDatatypeQuery.java
License:Apache 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("json"); final String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/*from w ww .j a v a2s . c om*/ }
From source file:org.sindice.siren.solr.qparser.TestDefaultOperator.java
License:Apache 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);/*w ww. j a v a2 s . c o m*/ query = new SolrQuery(); query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }"); query.setRequestHandler("json"); results = this.search(query, URL_FIELD); // Default Operator = AND : Only one document should match assertEquals(1, results.length); }
From source file:org.sindice.siren.solr.qparser.TestDefaultOperator.java
License:Apache 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 ww. j a va 2s.com query = new SolrQuery(); query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }"); query.setRequestHandler("json"); 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:org.sindice.siren.solr.qparser.TestJsonQParser.java
License:Apache License
public void testNullJsonQuery() throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setRequestHandler("json"); this.search(query, ID_FIELD); }
From source file:org.sindice.siren.solr.qparser.TestJsonQParser.java
License:Apache License
@Test(expected = SolrException.class) public void testEmptyJsonQuery() throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setQuery(" "); query.setRequestHandler("json"); this.search(query, ID_FIELD); }
From source file:org.sindice.siren.solr.qparser.TestJsonQParser.java
License:Apache License
@Test(expected = SolrException.class) public void testBadJsonQuery() throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setQuery(" { aaa : } "); query.setRequestHandler("json"); this.search(query, ID_FIELD); }
From source file:org.sindice.siren.solr.qparser.TestJsonQParser.java
License:Apache License
@Test public void testSimpleJsonQuery() throws IOException, SolrServerException, QueryNodeException { this.addJsonString("1", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); SolrQuery query = new SolrQuery(); final QueryBuilder b = new QueryBuilder(); query.setQuery(b.newTwig("aaa").with(b.newNode("ccc"), 3).toString()); query.setRequestHandler("json"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);// w w w .j av a2 s . co m query = new SolrQuery(); query.setQuery(b.newTwig("aaa").with(b.newNode("ccc"), 2).toString()); query.setRequestHandler("json"); results = this.search(query, ID_FIELD); assertEquals(0, results.length); }