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.TestKeywordQParser.java
License:Open Source License
@Test public void testQNamesMapping() throws SolrServerException, IOException { this.addJsonString("1", "{ \"uri\" : { " + "\"_value_\" : \"http://xmlns.com/foaf/0.1/Person\", " + "\"_datatype_\" : \"uri\" " + "} }"); final SolrQuery query = new SolrQuery(); query.setQuery(" uri : 'foaf:Person' "); query.setRequestHandler("keyword"); final String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/* w w w .j a v a2s . co m*/ }
From source file:com.sindicetech.siren.solr.qparser.TestMultiFieldQuery.java
License:Open Source License
@Test public void testMultiFieldQuery() throws SolrServerException, IOException { SolrInputDocument document = new SolrInputDocument(); document.addField(ID_FIELD, "1"); document.addField(JSON_FIELD + 1, "{ \"aaa\" : \"bbb\" }"); document.addField(JSON_FIELD + 2, "{ \"aaa\" : \"ccc\" }"); getWrapper().add(document);/*ww w . j a v a 2 s . c o m*/ document = new SolrInputDocument(); document.addField(ID_FIELD, "2"); document.addField(JSON_FIELD + 1, "{ \"aaa\" : \"ccc\" }"); document.addField(JSON_FIELD + 2, "{ \"aaa\" : \"bbb\" }"); getWrapper().add(document); getWrapper().commit(); final SolrQuery query = new SolrQuery(); query.setQuery(" aaa : ccc "); query.setRequestHandler("keyword"); query.set(SirenParams.QF, JSON_FIELD + 1, JSON_FIELD + 2); final String[] results = getWrapper().search(query, ID_FIELD); assertEquals(2, results.length); }
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 . java 2 s. c om*/ */ @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. java2 s . c om 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 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 . j a v a 2 s .c om 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.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 .ja v a 2s . co 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 ww. j a v a2 s . c o m*/ 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 a2s .c o 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); } }