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

项目: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());
}
项目: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 SearchRequest buildRequest(SearchQuery searchQuery, Localization localization) {
    SearchRequest request = new SearchRequest();
    request.setQuery(searchQuery.getQueryDetails().getQueryText());
    request.setStart((long) (searchQuery.getStart() - 1));
    request.setSize((long) searchQuery.getPageSize());
    request.setFilterQuery("publicationid:'" + localization.getId() + "'");
    request.putCustomQueryParameter("q.options", QUERY_OPTIONS);
    request.putCustomQueryParameter("highlight.body", HIGHLIGHT_SETTINGS);
    request.putCustomQueryParameter("highlight.summary", HIGHLIGHT_SETTINGS);
    request.putCustomQueryParameter("highlight.title", HIGHLIGHT_SETTINGS);
    return request;
}
项目:dxa-modules    文件:AwsCloudSearchProvider.java   
@Override
public void executeQuery(SearchQuery searchQuery, Localization localization) {
    SearchRequest request = buildRequest(searchQuery, localization);
    processResults(searchQuery, getClient(localization).search(request));
}