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.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 w w w . ja v a2s. com }
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 www . j a v a 2s. 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);//from w w w . j a v a2 s .c om 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); }
From source file:com.sindicetech.siren.solr.qparser.TestExtendedTreeQParser.java
License:Open Source License
@Test(expected = SolrException.class) public void testEmptyJsonQuery() throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setQuery(" "); query.setRequestHandler("tree"); this.search(query, ID_FIELD); }
From source file:com.sindicetech.siren.solr.qparser.TestExtendedTreeQParser.java
License:Open Source License
@Test(expected = SolrException.class) public void testBadJsonQuery() throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setQuery(" { aaa : } "); query.setRequestHandler("tree"); this.search(query, ID_FIELD); }
From source file:com.sindicetech.siren.solr.qparser.TestExtendedTreeQParser.java
License:Open Source 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("tree"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/*from ww w. java 2 s.co m*/ query = new SolrQuery(); query.setQuery(b.newTwig("aaa").with(b.newNode("ccc"), 2).toString()); query.setRequestHandler("tree"); results = this.search(query, ID_FIELD); assertEquals(0, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestExtendedTreeQParser.java
License:Open Source License
@Test public void testQNamesMapping() 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("'foaf:Person'")).toString()); query.setRequestHandler("tree"); final String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/*from w w w.jav a 2 s . c om*/ }
From source file:com.sindicetech.siren.solr.qparser.TestExtendedTreeQParser.java
License:Open Source License
/** * Checks the qparser plugin option to allow leading wildcard. The solrconfig.xml is setting this parameter * to true./* w ww . ja v a2s .co m*/ */ @Test public void testAllowLeadingWildcard() throws SolrServerException, IOException, QueryNodeException { this.addJsonString("1", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); final SolrQuery query = new SolrQuery(); final QueryBuilder b = new QueryBuilder(); query.setQuery(b.newNode("*a*").toString()); query.setRequestHandler("tree"); final String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestKeywordQParser.java
License:Open Source License
@Test(expected = SolrException.class) public void testBadKeywordQuery() throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setQuery(" aaa : [ * : ccc } "); query.setRequestHandler("keyword"); this.search(query, ID_FIELD); }
From source file:com.sindicetech.siren.solr.qparser.TestKeywordQParser.java
License:Open Source License
@Test public void testSimpleKeywordQuery() throws SolrServerException, IOException { this.addJsonString("1", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); this.addJsonString("2", "{ \"aaa\" : \"ddd eee\" }"); SolrQuery query = new SolrQuery(); query.setQuery(" aaa : { * : ccc } "); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/*from www . ja v a 2 s. co m*/ query = new SolrQuery(); query.setQuery(" aaa : ddd "); query.setRequestHandler("keyword"); results = this.search(query, ID_FIELD); assertEquals(1, results.length); }