private void readNextPage() { queryManager.search(stringQueryDefinition, searchHandle, documentCounter); currentPage = searchHandle.getMatchResults(); }
private void readNextPage() { queryManager.search(stringQueryDefinition, searchHandle, documentCounter); currentPage = searchHandle.getMatchResults(); }
public List<String> getUrisInCollection(String collectionName, int pageLength) { QueryManager mgr = getClient().newQueryManager(); mgr.setPageLength(pageLength); StringQueryDefinition def = mgr.newStringDefinition(); def.setCollections(collectionName); SearchHandle h = mgr.search(def, new SearchHandle()); List<String> uris = new ArrayList<String>(); for (MatchDocumentSummary s : h.getMatchResults()) { uris.add(s.getUri()); } return uris; }
public long getCollectionSize(String collectionName) { QueryManager queryMgr = getClient().newQueryManager(); StringQueryDefinition def = queryMgr.newStringDefinition(); def.setCollections(collectionName); SearchHandle sh = queryMgr.search(def, new SearchHandle()); return sh.getTotalResults(); }
public SearchHandle runSearch(DatabaseClient client, String queryOptionName, String criteria) { // create a manager for searching QueryManager queryMgr = client.newQueryManager(); // create a search definition StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName); querydef.setCriteria(criteria); // create a handle for the search results SearchHandle resultsHandle = new SearchHandle(); // run the search return queryMgr.search(querydef, resultsHandle); }
@Override public int getJobInstanceCount(String jobName) throws NoSuchJobException { StructuredQueryBuilder qb = new StructuredQueryBuilder(SEARCH_OPTIONS_NAME); StructuredQueryDefinition querydef = qb.and( qb.valueConstraint("jobName", jobName), qb.collection(COLLECTION_JOB_INSTANCE) ); QueryManager queryMgr = databaseClient.newQueryManager(); SearchHandle results = queryMgr.search(querydef, new SearchHandle()); int count = (int) results.getTotalResults(); if (count == 0) { throw new NoSuchJobException(jobName + " not found"); } else { return count; } }
private void check(StructureWriteHandle handle, String optionsName) { RawCombinedQueryDefinition rawCombinedQueryDefinition; if (optionsName == null) { rawCombinedQueryDefinition = queryMgr.newRawCombinedQueryDefinition(handle); } else { rawCombinedQueryDefinition = queryMgr.newRawCombinedQueryDefinition(handle, optionsName); } // StringHandle stringResults = null; // stringResults = queryMgr.search(rawCombinedQueryDefinition, // new StringHandle()); // System.out.println(stringResults.get()); SearchHandle results; results = queryMgr.search(rawCombinedQueryDefinition, new SearchHandle()); checkResults(results); }
@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 test_issue581_RawStructuredQueryFromFileHandle() throws Exception { Common.client.newDocumentManager().write("test_issue581_RawStructuredQueryFromFileHandle.xml", new FileHandle(new File("src/test/resources/constraint5.xml")).withFormat(Format.XML)); // get the combined query File file = new File("src/test/resources/combinedQueryOption.xml"); // create a handle for the search criteria FileHandle rawHandle = new FileHandle(file); QueryManager queryMgr = Common.client.newQueryManager(); // create a search definition based on the handle RawStructuredQueryDefinition querydef = queryMgr.newRawStructuredQueryDefinition(rawHandle); // create result handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(querydef, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("0026", "string(//*[local-name()='result'][1]//*[local-name()='id'])", resultDoc); }
private void check(StructureWriteHandle handle, String optionsName) { QueryManager queryMgr = Common.client.newQueryManager(); queryMgr.setPageLength(0); RawCombinedQueryDefinition query = queryMgr.newRawCombinedQueryDefinition(handle); SearchHandle response = queryMgr.search(query, new SearchHandle()); String wrappedCtsQuery = response.getQuery(new StringHandle()).get(); // remove the <search:query> wrapper element String ctsQuery = wrappedCtsQuery.replaceAll("</?search:query[^>]*>", ""); long numMatches = response.getTotalResults(); checkCts(new StringHandle(ctsQuery), optionsName, numMatches); }
@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() 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 test105Searches() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); for (int i=0;i<105;i++) { for (QueryDefinition t : new QueryDefinition[] { qb.term("leaf3"), qb.build(qb.value(qb.element("leaf"), "leaf3")) }) { JacksonHandle results = queryMgr.search(t, new JacksonHandle()); assertNotNull(results); JsonNode jsonResults =results.get(); @SuppressWarnings("unused") String resultString = results.getMapper().writeValueAsString(jsonResults); // ignore. } } }
@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); }
@Ignore public void testGeospatialRegionQuery() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/country/region")), GeospatialOperator.CONTAINS, qb.point(19.429297983081977, -99.140625)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); for (MatchDocumentSummary summary : summaries) { assertEquals("mexico.xml", summary.getUri()); } }
@Ignore public void testFloatPrecisionCoordinateSystem() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "coordinate-system=wgs84"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(2, summaries.length); }
@Ignore public void testDoublePrecisionCoordinateSystem() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "coordinate-system=wgs84/double"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(1, summaries.length); }
@Ignore public void testFloatPrecision() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "precision=float"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(2, summaries.length); }
@Ignore public void testDoublePrecision() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "precision=double"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(1, summaries.length); }
@Test public void testStructuredSearch2() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); EditableNamespaceContext namespaces = new EditableNamespaceContext(); namespaces.put("x", "root.org"); namespaces.put("y", "target.org"); StructuredQueryBuilder qb = new StructuredQueryBuilder(namespaces); StructuredQueryDefinition qdef = qb.geospatial( qb.geoPath(qb.pathIndex("/x:geo/y:path")), qb.box(1, 2, 3, 4)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); assertNotNull(results); MatchDocumentSummary[] summaries = results.getMatchResults(); assertTrue(summaries == null || summaries.length == 0); }