@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()); }
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()); }
private static SearchItem convertToSearchItem(Hit hit) { SearchItem item = new SearchItem(); String id = hit.getId(); Map<String, String> highlights = hit.getHighlights(); item.setId(id); String summary = highlights.get("summary"); item.setSummary(isEmpty(summary) ? highlights.get("body") : summary); item.setTitle(highlights.get("title")); item.setUrl(hit.getFields().get("url").get(0)); return item; }