/** * 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; }
/** * 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; }
@Test public void testConciseTreeAttributeWildcard() throws IOException, SolrServerException, QueryNodeException { this.addJsonString("1", "concise-attribute-wildcard", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); SolrQuery query = new SolrQuery(); final ConciseQueryBuilder b = new ConciseQueryBuilder(); query.setQuery(b.newNode("ccc").toString()); query.setRequestHandler("tree"); query.set("qf", "concise-attribute-wildcard"); 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); }
/** * 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); }
/** * 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); }