@Test public void testJSON() throws FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException { String optionsName = writeOptions(); QueryManager queryMgr = Common.client.newQueryManager(); StringQueryDefinition qdef = queryMgr.newStringDefinition(optionsName); qdef.setCriteria("grandchild1 OR grandchild4"); qdef.setDirectory("/sample/"); queryMgr.setView(QueryView.FACETS); // create a handle for the search results StringHandle resultsHandle = new StringHandle().withFormat(Format.JSON); // run the search queryMgr.search(qdef, resultsHandle); assertEquals("{", resultsHandle.get().substring(0, 1)); // It's JSON, right? }
@Test public void testFailedSearch() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); queryMgr.setView(QueryView.RESULTS); StringQueryDefinition qdef = queryMgr.newStringDefinition(); qdef.setCriteria("criteriaThatShouldNotMatchAnyDocument"); qdef.setDirectory("/sample/"); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); assertNotNull(results); MatchDocumentSummary[] summaries = results.getMatchResults(); assertTrue(summaries == null || summaries.length == 0); }
@Test public void testStringSearch2() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); StringQueryDefinition qdef = queryMgr.newStringDefinition(); qdef.setCriteria("10"); qdef.setDirectory("/sample/"); SearchHandle handle = new SearchHandle(); handle = queryMgr.search(qdef, handle); assertNotNull(handle); MatchDocumentSummary[] summaries = handle.getMatchResults(); assertNotNull(summaries); assertEquals("expected 2 results", 2, 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()); } } }
@Test public void testStringSearch() throws IOException, ParserConfigurationException, SAXException, FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException { String optionsName = writeOptions(); QueryManager queryMgr = Common.client.newQueryManager(); StringQueryDefinition qdef = queryMgr.newStringDefinition(optionsName); qdef.setCriteria("grandchild1 OR grandchild4"); qdef.setDirectory("/sample/"); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); assertNotNull(results); assertFalse(results.getMetrics().getTotalTime() == -1); FacetResult[] facets = results.getFacetResults(); assertNotNull(facets); assertEquals("expected 1 facet", 1, facets.length); FacetValue[] facetVals = facets[0].getFacetValues(); assertEquals("expected 6 facet values", 6, facetVals.length); MatchDocumentSummary[] summaries = results.getMatchResults(); assertNotNull(summaries); assertEquals("expected 2 results", 2, summaries.length); }
@Test public void testStringSearch4() throws IOException, FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException { String optionsName = writeOptions(); QueryManager queryMgr = Common.client.newQueryManager(); StringQueryDefinition qdef = queryMgr.newStringDefinition(optionsName); qdef.setCriteria("grandchild1 OR grandchild4"); qdef.setDirectory("/sample/"); queryMgr.setView(QueryView.FACETS); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); assertNotNull(results); FacetResult[] facets = results.getFacetResults(); assertNotNull(facets); assertEquals("expected 1 facet", 1, facets.length); FacetValue[] facetVals = facets[0].getFacetValues(); assertEquals("expected 6 facet values", 6, facetVals.length); MatchDocumentSummary[] summaries = results.getMatchResults(); assertTrue(summaries == null || summaries.length == 0); queryMgr.setView(QueryView.RESULTS); results = queryMgr.search(qdef, new SearchHandle()); assertNotNull(results); facets = results.getFacetResults(); assertTrue(facets == null || facets.length == 0); summaries = results.getMatchResults(); assertNotNull(summaries); assertEquals("expected 2 results", 2, summaries.length); assertEquals("empty-snippet", results.getSnippetTransformType()); }
StringQueryDefinition qd = queryMgr.newStringDefinition(); qd.setCriteria("bar"); qd.setDirectory(DIRECTORY);
StringQueryDefinition query = runtimeDbQueryMgr.newStringDefinition(); query.setCriteria("hello2"); query.setDirectory("/test/"); MatchDocumentSummary match = runtimeDbQueryMgr.findOne(query); assertNotNull("Should get a doc back", match);