List of usage examples for org.apache.solr.client.solrj SolrQuery SolrQuery
public SolrQuery()
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
/** * When no local parameters are defined, then it should rely on the default * solr parser (i.e., lucene)./*from w ww. j a va2s . co m*/ */ @Test public void testNoLocalParamater() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : \"bbb\" }"); final SolrQuery query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", URL_FIELD + ":1"); query.setRequestHandler("keyword"); final String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
@Test public void testSimpleNestedLuceneQuery() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : \"bbb\" }"); SolrQuery query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", "{!lucene}" + URL_FIELD + ":1"); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);//from ww w . ja v a 2 s.c o m query = new SolrQuery(); query.setQuery("aaa : bbb"); // non existing document id query.setParam("nested", "{!lucene}" + URL_FIELD + ":2"); query.setRequestHandler("keyword"); results = this.search(query, ID_FIELD); assertEquals(0, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
@Test public void testEmptyMainQueryWithNestedMatchAll() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : \"bbb\" }"); SolrQuery query = new SolrQuery(); query.setParam("nested", "{!lucene} *:*"); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/*from ww w.j a v a 2 s. c o m*/ }
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
@Test public void testMultipleNestedQuery() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : [\"bbb\", \"ccc\"] }"); SolrQuery query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", "{!lucene}" + URL_FIELD + ":1", "{!keyword} aaa : ccc"); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);//from w w w .jav a 2 s . com query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", "{!lucene}" + URL_FIELD + ":1", "{!keyword} aaa : ddd"); query.setRequestHandler("keyword"); results = this.search(query, ID_FIELD); assertEquals(0, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java
License:Open Source License
@Test public void testCurlyBracketInNestedQuery() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); SolrQuery query = new SolrQuery(); query.setParam("nested", "{!keyword} aaa : { bbb : ccc } "); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/*from ww w. j a va 2s . c o m*/ query = new SolrQuery(); query.setParam("nested", "{!tree} { \"node\" : { \"query\" : \"ccc\" } }"); query.setRequestHandler("keyword"); results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
From source file:com.sindicetech.siren.solr.qparser.TestURIQuery.java
License:Open Source License
@Test public void testTildeInURI() throws IOException, SolrServerException { this.addJsonString("1", " { \"uri\" : { " + "\"_value_\" : \"http://sw.deri.org/~aidanh/\", " + "\"_datatype_\" : \"uri\"" + " } }"); SolrQuery query = new SolrQuery(); query.setQuery("uri('http://sw.deri.org/~aidanh/')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); // test uri trailing slash filter query = new SolrQuery(); query.setQuery("uri('http://sw.deri.org/~aidanh/')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); }
From source file:com.sindicetech.siren.solr.qparser.TestURIQuery.java
License:Open Source License
@Test public void testEncodedURI() throws IOException, SolrServerException { this.addJsonString("1", " { \"uri\" : { " + "\"_value_\" : \"http://dblp.l3s.de/d2r/resource/authors/Knud_M%C3%B6ller\", " + "\"_datatype_\" : \"uri\"" + " } }"); // testing search of plain URI search SolrQuery query = new SolrQuery(); query.setQuery("uri('http://dblp.l3s.de/d2r/resource/authors/Knud_M%C3%B6ller')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); // testing search of decoded local name token query = new SolrQuery(); query.setQuery("Mller"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query).getNumFound()); }
From source file:com.sindicetech.siren.solr.response.TestSirenTransformer.java
License:Open Source License
@Test public void testTransformer() throws SolrServerException, IOException { SolrInputDocument document = new SolrInputDocument(); document.addField(ID_FIELD, "1"); document.addField(JSON_FIELD, json); getWrapper().add(document);/*ww w .j av a 2 s . c o m*/ getWrapper().commit(); String queryStr = "{" + "\"twig\" : { " + "\"root\" : \"director\"," + "\"child\" : [{\"occur\":\"MUST\"," + "\"twig\": {" + "\"child\":[{\"occur\":\"MUST\"," + "\"twig\": {" + "\"root\":\"first_name\"," + "\"child\":[" + "{\"occur\":\"MUST\"," + "\"node\" : { \"query\" : \"Clint\" } " + "}" + "]" + "}" + "}" + "]" + "}" + "}" + ", {\"occur\" : \"MUST\", \"variable\" : {}}" + "]" + "}" + "}"; final SolrQuery query = new SolrQuery(); query.setQuery(queryStr); query.setRequestHandler("tree"); query.set(SirenParams.QF, JSON_FIELD); query.set("fl", "id,json,[sirenProjection]"); final String[] results = getWrapper().search(query, JSON_FIELD); assertEquals(1, results.length); assertEquals("{\"director\":{\"last_name\":\"Eastwood\",\"first_name\":\"Clint\",\"birth_date\":\"1930\"}}", results[0]); }
From source file:com.sindicetech.siren.solr.SolrServerWrapper.java
License:Open Source License
public String[] search(final String q, final String retrievedField, final String qt) throws SolrServerException, IOException { final SolrQuery query = new SolrQuery(); query.setRequestHandler(qt);/* w w w . ja v a 2 s . com*/ query.setQuery(q); return this.search(query, retrievedField); }
From source file:com.sitewhere.connectors.solr.search.SolrSearchProvider.java
License:Open Source License
@Override public List<IDeviceEvent> executeQuery(String queryString) throws SiteWhereException { try {/*from w w w .ja v a 2s.co m*/ LOGGER.debug("About to execute Solr search with query string: " + queryString); List<IDeviceEvent> results = new ArrayList<IDeviceEvent>(); SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(queryString); QueryResponse response = getSolr().getSolrClient().query(solrQuery); SolrDocumentList docs = response.getResults(); for (SolrDocument doc : docs) { results.add(SiteWhereSolrFactory.parseDocument(doc)); } return results; } catch (SolrServerException e) { throw new SiteWhereException("Unable to execute query.", e); } catch (IOException e) { throw new SiteWhereException("Unable to execute query.", e); } }