@Test public void testFailedSearch() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition qdef = qb.term("criteriaThatShouldNotMatchAnyDocument"); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); assertNotNull(results); MatchDocumentSummary[] summaries = results.getMatchResults(); assertTrue(summaries == null || summaries.length == 0); }
@Test public void testJSON() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.term("leaf3"); // create a handle for the search results StringHandle resultsHandle = new StringHandle().withFormat(Format.JSON); // run the search queryMgr.search(t, resultsHandle); assertEquals("{", resultsHandle.get().substring(0, 1)); // It's JSON, right? }
@Test public void testStructuredSearch1() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); for (QueryDefinition t : new QueryDefinition[] {qb.term("leaf3"), qb.build(qb.value(qb.element("leaf"), "leaf3"))}) { MatchDocumentSummary summary = queryMgr.findOne(t); assertNotNull(summary); GenericDocumentManager docMgr = Common.client.newDocumentManager(); assertNotNull("Document exists", docMgr.exists(summary.getUri())); } }
@Test public void testStructuredSearch() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); for (QueryDefinition t : new QueryDefinition[] {qb.term("leaf3"), qb.build(qb.value(qb.element("leaf"), "leaf3"))}) { SearchHandle results = queryMgr.search(t, new SearchHandle()); assertNotNull(results); assertFalse(results.getMetrics().getTotalTime() == -1); MatchDocumentSummary[] summaries = results.getMatchResults(); assertNotNull(summaries); assertEquals("expected 1 result", 1, summaries.length); for (MatchDocumentSummary summary : summaries) { MatchLocation[] locations = summary.getMatchLocations(); assertEquals("expected 1 match location", 1, locations.length); for (MatchLocation location : locations) { assertNotNull(location.getAllSnippetText()); } } } }