public String returnSearchResult(SearchHandle resultsHandle) { String matchedDoc = ""; // iterate over the result documents MatchDocumentSummary[] docSummaries = resultsHandle.getMatchResults(); for (MatchDocumentSummary docSummary : docSummaries) { String uri = docSummary.getUri(); // iterate over the match locations within a result document MatchLocation[] locations = docSummary.getMatchLocations(); matchedDoc = matchedDoc + "|" + "Matched " + locations.length + " locations in " + uri; } return matchedDoc; }
private void checkResults(SearchHandle results) { assertNotNull(results); assertFalse(results.getMetrics().getTotalTime() == -1); MatchDocumentSummary[] summaries = results.getMatchResults(); assertNotNull(summaries); assertTrue(summaries.length > 0); for (MatchDocumentSummary summary : summaries) { assertTrue("Mime type of document", summary.getMimeType().matches("(application|text)/xml")); assertEquals("Format of document", Format.XML, summary.getFormat()); Document relevanceTrace = summary.getRelevanceInfo(); if (relevanceTrace != null) { assertEquals(relevanceTrace.getDocumentElement().getLocalName(),"relevance-info"); } MatchLocation[] locations = summary.getMatchLocations(); for (MatchLocation location : locations) { assertNotNull(location.getAllSnippetText()); } } }
MatchLocation[] locations = docSummary.getMatchLocations(); assertEquals("Document location difference", "/searchOnProps/" + file.getPath(), uri);
@Test(expected = UnsupportedOperationException.class) public void testBulkSearchSQDwithWrongResponseFormat() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadTxtDocuments(); TextDocumentManager docMgr = client.newTextDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StringQueryDefinition qd = queryMgr.newStringDefinition(); qd.setCriteria("bar"); docMgr.setNonDocumentFormat(Format.JSON); SearchHandle results = new SearchHandle(); DocumentPage page = docMgr.search(qd, 1, results); MatchDocumentSummary[] summaries = results.getMatchResults(); for (MatchDocumentSummary summary : summaries) { MatchLocation[] locations = summary.getMatchLocations(); for (MatchLocation location : locations) { System.out.println(location.getAllSnippetText()); // do something with the snippet text } } }
private void checkCts(CtsQueryWriteHandle handle, String optionsName, long numMatches) { RawCtsQueryDefinition rawCtsQueryDefinition; if (optionsName == null) { rawCtsQueryDefinition = queryMgr.newRawCtsQueryDefinition(handle); } else { rawCtsQueryDefinition = queryMgr.newRawCtsQueryDefinition(handle, optionsName); } SearchHandle results; results = queryMgr.search(rawCtsQueryDefinition, new SearchHandle()); assertNotNull(results); assertEquals(results.getTotalResults(), numMatches); assertFalse(results.getMetrics().getTotalTime() == -1); MatchDocumentSummary[] summaries = results.getMatchResults(); assertNotNull(summaries); assertTrue(summaries.length > 0); for (MatchDocumentSummary summary : summaries) { assertTrue("Mime type of document", summary.getMimeType().matches("(application|text)/xml")); assertEquals("Format of document", Format.XML, summary.getFormat()); MatchLocation[] locations = summary.getMatchLocations(); for (MatchLocation location : locations) { assertNotNull(location.getAllSnippetText()); } } }
@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 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()); } } } }