Java 类com.amazonaws.services.cloudsearchdomain.model.SearchResult 实例源码

项目:mosquito-report-api    文件:Indexer.java   
public List<ObjectNode> search(String latlonnw, String latlonse) {
    String[] latlonnwa = latlonnw.split(",");
    String[] latlonsea = latlonse.split(",");

    Double latnw = Double.parseDouble(latlonnwa[0]);
    Double lonnw = Double.parseDouble(latlonnwa[1]);

    Double latse = Double.parseDouble(latlonsea[0]);
    Double lonse = Double.parseDouble(latlonsea[1]);

    String latlon = (latnw - ((latnw - latse) / 2)) + "," + (lonnw - ((lonnw - lonse) / 2));

    SearchRequest request = new SearchRequest().withSize(30L)
            .withQuery("latlon:['" + latlonnw + "','" + latlonse + "']")
            .withExpr("{\"distance\":\"haversin(" + latlon + ",latlon.latitude,latlon.longitude)\"}")
            .withSort("distance asc");

    request.setQueryParser(QueryParser.Structured);

    SearchResult result = domain.search(request);

    return result.getHits().getHit().stream().map(hit -> {
        return hit.getFields().entrySet().stream().collect(new EntrySetStringStringSetToObjectNodeCollector());
    }).collect(Collectors.toList());
}
项目:mosquito-report-api    文件:IndexerTest.java   
@Test
public void testSearchCenter() {
    when(amazonCloudSearch.describeDomains(any())).thenReturn(new DescribeDomainsResult()
            .withDomainStatusList(Lists.newArrayList(new DomainStatus().withSearchService(new ServiceEndpoint().withEndpoint("http://localhost")))));

    HashMap<String, List<String>> map = Maps.newHashMap();
    map.put("property", Lists.newArrayList("value"));
    SearchResult expected = new SearchResult().withHits(new Hits().withHit(new Hit().withFields(map)));

    ArgumentCaptor<SearchRequest> requestCaptor = ArgumentCaptor.forClass(SearchRequest.class);

    when(domain.search(requestCaptor.capture())).thenReturn(expected);

    List<ObjectNode> result = getService(ModelIndexer.class).searchCenter("0,0");

    SearchRequest request = requestCaptor.getValue();

    assertEquals("value", result.get(0).get("property").asText());
    assertEquals("latlon:['0.1,-0.1','-0.1,0.1']", request.getQuery());
    assertEquals("{\"distance\":\"haversin(0.0,0.0,latlon.latitude,latlon.longitude)\"}", request.getExpr());
    assertEquals("distance asc", request.getSort());
    assertEquals(Long.valueOf(30L), request.getSize());
}
项目:mcs    文件:MatchmakerCloudSearchServiceController.java   
@RequestMapping(value = "/" + restResourceName, method = RequestMethod.GET, produces = "application/json")
@ResponseStatus(value = HttpStatus.OK)
public @ResponseBody String search(
    @RequestParam (value = "query", required = true) String query)
    throws Exception {

  String response = null;
  SearchResult documents = null;

  try {
    MCSQuery mcsQuery = objectMapper.readValue(query, MCSQuery.class);
    documents = cloudSearchService.structuredSearch(mcsQuery);
    response = objectMapper.writeValueAsString(documents);
  } catch (Exception e) {
    logger.error("", e);
  }
  return response;
}
项目:mcs    文件:CloudSearchServiceTest.java   
@Test
public void testSearch() throws Exception {
  long numResults = 10;
  for (String queryString : queryStrings) {
    for (String facet : facetStrings) {
      MCSQuery query = new MCSQuery();
      query.queryString = queryString;
      query.facets = facet;
      query.numRecordsToReturn = numResults;
      SearchResult result = cloudSearchService.structuredSearch(query);
      Assert.assertNotNull(result);
      Assert.assertTrue(result.getHits().getFound() > 0);
      logger.info("RESULT:::::: " + result.toString());
    }
  }
}
项目:mcs    文件:CloudSearchServiceTest.java   
@Test
public void testPaginatedSearch() throws Exception {
  long numResults = 52;

  MCSQuery query = new MCSQuery();
  query.queryString = queryFour;
  query.facets = facetThree;
  query.numRecordsToReturn = numResults;
  SearchResult result = null;
  long lastStartIndex = -1;
  long count = 0;
  do {
    result = cloudSearchService.structuredSearch(query);
    Assert.assertNotNull(result);
    Assert.assertTrue(result.getHits().getFound() >= 0);
    count += result.getHits().getHit().size();
    Assert.assertEquals(result.getFacets().size(), 2);
    Assert.assertTrue(result.getHits().getStart() > lastStartIndex);
    lastStartIndex = result.getHits().getStart();
    query.cursor = result.getHits().getCursor();
  } while (result.getHits().getHit().size() > 0);
  // Assuming the results do not change when this test is executed, the next line must be true
  Assert.assertEquals(result.getHits().getFound().longValue(), count);
}
项目:spring-boot-aws-cloudsearch    文件:CloudSearchClient.java   
public List<SearchResult> search(String domainName, SearchRequest searchRequest) {
    AmazonCloudSearchDomainAsyncClient domainClient = cloudSearchDomainAsyncClients.get(domainName);
    if (domainClient == null) {
        throw new IllegalArgumentException(domainName + " not known");
    }
    if (progressListener != null) {
        searchRequest.setGeneralProgressListener(progressListener);
    }
    List<SearchResult> searchResults = new ArrayList<>();
    int found = 0;
    while (true) {
        SearchResult searchResult = domainClient.search(searchRequest);
        searchResults.add(searchResult);
        Hits hits = searchResult.getHits();
        log.debug("found {} {}", found, hits.getFound());
        int size = hits.getHit().size();
        found += size;
        if (size == 0 || hits.getFound() == found || hits.getCursor() == null) {
            break;
        }
        searchRequest.setCursor(hits.getCursor());
    }
    return searchResults;
}
项目:dxa-modules    文件:AwsCloudSearchProvider.java   
private static void processResults(SearchQuery searchQuery, SearchResult result) {
    List<Hit> list = result.getHits().getHit();
    List<SearchItem> items = new ArrayList<>(list.size());
    for (Hit hit : list) {
        items.add(convertToSearchItem(hit));
    }

    searchQuery.setResults(items);

    searchQuery.setTotal(result.getHits().getFound());
}