/** * A query that shows how to use range query on geo-location data (double) */ private SolrQuery getGeoQuery() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("ChargeDeviceLocation") .with(b.newNode("xsd:double([52 TO 53])").setAttribute("Latitude")) .with(b.newNode("xsd:double([-2 TO 2])").setAttribute("Longitude")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); return query; }
/** * Get a list of queries that are based on the JSON query syntax * * @see com.sindicetech.siren.qparser.tree.ExtendedTreeQueryParser */ private String[] getJsonQueries() throws QueryNodeException { final ConciseQueryBuilder b = new ConciseQueryBuilder(); final String[] queries = { b.newNode("Cambridge").toString(), b.newNode("Cambridge").setAttribute("placeOfPublication").toString(), b.newNode("Cambridge Scholars").setAttribute("publisher").toString(), b.newNode("Environmental").setAttribute("subject").toString(), b.newBoolean().with(b.newNode("Environmental").setAttribute("subject")) .with(b.newNode("2009").setAttribute("issued")).toString(), // search an attribute with two different values b.newBoolean().with(b.newNode("text").setAttribute("type")) .with(b.newNode("monographic").setAttribute("type")).toString(), b.newTwig("identifier").with(b.newNode("9780852935392").setAttribute("id")) .with(b.newNode("isbn").setAttribute("type")).toString(), b.newBoolean().with(b.newNode("Computer security").setAttribute("subject")) .with(b.newTwig("isPartOf").with( b.newTwig("identifier").with( b.newNode("'0302-9743'").setAttribute("id") ) )).toString() }; return queries; }
/** * A query that shows how to use range query on long numeric value */ private SolrQuery getOutputCurrentQuery() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); TwigQuery twig1 = b.newTwig("ChargeDeviceLocation") .with(b.newNode("xsd:double([52 TO 53])").setAttribute("Latitude")) .with(b.newNode("xsd:double([-2 TO 2])").setAttribute("Longitude")); TwigQuery twig2 = b.newTwig("Connector") .with(b.newNode("xsd:long([32 TO *])").setAttribute("RatedOutputCurrent")); String q = b.newBoolean() .with(twig1) .with(twig2) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); return query; }
/** * Get a list of queries that are based on the JSON query syntax * * @see com.sindicetech.siren.qparser.tree.ExtendedTreeQueryParser */ private String[] getJsonQueries() throws QueryNodeException { final ConciseQueryBuilder b = new ConciseQueryBuilder(); final String[] queries = { b.newNode("\"Marie Antoinette\"").toString(), b.newNode("Drama").setAttribute("genre").toString(), b.newBoolean().with(b.newNode("Drama").setAttribute("genre")) .with(b.newNode("2010").setAttribute("year")).toString(), b.newTwig("director").with(b.newNode("Eastwood").setAttribute("last_name")) .with(b.newNode("Clint").setAttribute("first_name")).toString(), b.newBoolean().with(b.newTwig("actors").with(b.newNode("Timberlake"))) .with(b.newTwig("actors").with(b.newNode("Eisenberg"))).toString(), }; return queries; }
/** * A query that shows how to use a custom datatype (uri) */ private SolrQuery getWebsiteQuery() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("DeviceOwner") .with(b.newNode("uri(www.sourcelondon.net)").setAttribute("Website")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); return query; }
/** * A query that shows how to use the nested query parameter to use Solr's * query parsers on Solr's fields. */ private SolrQuery getNestedQuery() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("DeviceOwner") .with(b.newNode("uri(www.sourcelondon.net)").setAttribute("Website")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); query.setParam("nested", "{!lucene} ChargeDeviceName:university"); return query; }
/** * A query that shows how to combine SIREn query with the Solr's facet feature * on a Solr field. */ private SolrQuery getDeviceControllerFacet() throws QueryNodeException { ConciseQueryBuilder b = new ConciseQueryBuilder(); String q = b.newTwig("Connector") .with(b.newNode("xsd:long([32 TO *])").setAttribute("RatedOutputCurrent")) .toString(); final SolrQuery query = new SolrQuery(); query.setQuery(q); query.addFacetField("DeviceController.OrganisationName"); return query; }
@Test public void testNodeWithQuery() throws QueryNodeException { final ConciseQueryBuilder build = new ConciseQueryBuilder(); final NodeQuery node = build.newNode("bbb").setAttribute("aaa"); assertParser(node); }
/** * See #15 */ @Test public void testTwigWithSetAndUnsetAttribute() throws QueryNodeException { final ConciseQueryBuilder build = new ConciseQueryBuilder(); final TwigQuery twig = build.newTwig("funding") .with(build.newNode("a").setAttribute("round")) .with(build.newNode("2006")); assertParser(twig); }
@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()); query.setRequestHandler("tree"); query.set("qf", "concise"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
/** * Issue #66: The query parser applies lowercase the expanded terms */ @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); }
@Test public void testSimpleConciseTreeQuery() throws IOException, SolrServerException, QueryNodeException { this.addJsonString("1", "concise", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); query.setQuery(b.newTwig("aaa").with(b.newNode("ccc").setAttribute("bbb")).toString()); query.setRequestHandler("tree"); query.set("qf", "concise"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
/** * Check that the JSON document is correctly indexed in a SIREn's json field. */ @Test public void testJsonField() throws QueryNodeException, IOException, SolrServerException { String input = "{ \"id\" : \"1\", \"aaa\" : \"bbb\" }"; this.sendUpdateRequest(input); this.commit(); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); query.setQuery(b.newNode("bbb").setAttribute("aaa").toString()); query.setRequestHandler("tree"); long found = this.search(query).getNumFound(); assertEquals(1, found); }
.with( b.newTwig("http://www.w3.org/2000/01/rdf-schema#seeAlso") .with(b.newNode("'http://dbpedia/Person/2'").setAttribute("@id")), 1 b.newNode("Alfred Hitchkoc").setAttribute("http://www.w3.org/2000/01/rdf-schema#label"), 1 ).toString();
/** * Check if the field is stored as indicated by the fieldtype of the associated path-based mapper. */ @Test public void testStoredField() throws QueryNodeException, IOException, SolrServerException { String input = "{ \"id\" : \"1\", \"aaa\" : \"bbb\" }"; this.sendUpdateRequest(input); this.commit(); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); query.setQuery(b.newNode("bbb").setAttribute("aaa").toString()); query.setRequestHandler("tree"); query.setFields("aaa"); SolrDocumentList result = this.search(query); assertEquals(1, result.getNumFound()); assertNotNull(result.get(0).getFieldValue("aaa")); assertTrue(result.get(0).getFieldValue("aaa") instanceof ArrayList); assertEquals("bbb", ((ArrayList) result.get(0).getFieldValue("aaa")).get(0)); }
/** * Check that the nested query and the main query are intersected, i.e., that each one is assigned a MUST operator. * See issue #60. */ @Test public void testNestedQuery() throws IOException, SolrServerException, QueryNodeException { String input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM765\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }"; this.sendUpdateRequest(input); input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM556\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }"; this.sendUpdateRequest(input); input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM779\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }"; this.sendUpdateRequest(input); this.commit(); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); query.setQuery(b.newNode("CM765").setAttribute("ChargeDeviceRef").toString()); query.setParam("nested", "ChargeDeviceLocation.Address.PostTown:Peterborough"); query.setRequestHandler("tree"); long found = this.search(query).getNumFound(); assertEquals(1, found); }