use of alien4cloud.dao.model.FacetedSearchFacet in project alien4cloud by alien4cloud.
the class EsDaoPaginatedSearchTest method testFacetedSearchWellPaginated.
private void testFacetedSearchWellPaginated(int maxElement, int size, String searchText, Map<String, String[]> filters, String fetchContext) throws IOException {
List<NodeType> expectedDataList = new ArrayList<>(jndiTestDataList);
String facetNameToCheck;
String factetValueToCheck;
long expectedFacetCount = 0;
FacetedSearchResult<?> searchResp;
int expectedSize = 0;
boolean facetToCheckExist = false;
for (int from = 0; from < maxElement; from += size) {
expectedSize = (maxElement - from) > size ? size : maxElement - from;
searchResp = dao.facetedSearch(NodeType.class, searchText, filters, fetchContext, from, size);
assertNotNull(searchResp);
assertNotNull(searchResp.getTypes());
assertNotNull(searchResp.getData());
assertEquals(expectedSize, searchResp.getTypes().length);
assertEquals(expectedSize, searchResp.getData().length);
// testing the pertinence of returned data
Object[] data = searchResp.getData();
for (Object element : data) {
NodeType nt = jsonMapper.readValue(jsonMapper.writeValueAsString(element), NodeType.class);
// TODO assert fetch context result.
assertTrue(expectedDataList.contains(nt));
expectedDataList.remove(nt);
}
// test returned facets
if (filters != null && filters.containsKey("capabilities.type")) {
facetNameToCheck = "requirements.type";
factetValueToCheck = "network";
expectedFacetCount = 6;
} else {
facetNameToCheck = "capabilities.type";
factetValueToCheck = "war";
expectedFacetCount = 4;
}
assertNotNull(searchResp.getFacets());
assertTrue(!searchResp.getFacets().isEmpty());
FacetedSearchFacet[] facets = searchResp.getFacets().get(facetNameToCheck);
assertNotNull(facets);
long facetCount = 0;
for (FacetedSearchFacet facet : facets) {
if (facet.getFacetValue().equals(factetValueToCheck)) {
facetToCheckExist = true;
facetCount = facet.getCount();
}
}
assertTrue(facetToCheckExist);
assertEquals(expectedFacetCount, facetCount);
}
// assert the list is empty at the end.
assertTrue(expectedDataList.isEmpty());
}
use of alien4cloud.dao.model.FacetedSearchFacet in project alien4cloud by alien4cloud.
the class EsDaoSearchTest method facetedSearchTest.
@Test
public void facetedSearchTest() throws IndexingServiceException, JsonParseException, JsonMappingException, IOException, InterruptedException {
String searchText = "positive";
FacetedSearchResult searchResp = dao.facetedSearch(NodeType.class, searchText, null, 10);
assertNotNull(searchResp);
assertEquals(2, searchResp.getTotalResults());
assertEquals(2, searchResp.getTypes().length);
assertEquals(2, searchResp.getData().length);
String[] ids = new String[] { indexedNodeTypeTest.getId(), indexedNodeTypeTest4.getId() };
for (int i = 0; i < searchResp.getData().length; i++) {
NodeType idnt = (NodeType) searchResp.getData()[i];
assertElementIn(idnt.getId(), ids);
}
// test facets
Map<String, FacetedSearchFacet[]> mapp = searchResp.getFacets();
FacetedSearchFacet[] capaFacets = mapp.get("capabilities.type");
assertNotNull(capaFacets);
boolean warExist = false;
long warCount = 0;
for (int i = 0; i < capaFacets.length; i++) {
if (capaFacets[i].getFacetValue().equals("war")) {
warExist = true;
warCount = capaFacets[i].getCount();
}
}
assertTrue(warExist);
assertEquals(2, warCount);
// faceted search with filters
Map<String, String[]> filters = new HashMap<String, String[]>();
filters.put("capabilities.type", new String[] { "container" });
searchResp = dao.facetedSearch(NodeType.class, searchText, filters, 10);
assertNotNull(searchResp);
assertEquals(1, searchResp.getTotalResults());
assertEquals(1, searchResp.getTypes().length);
assertEquals(1, searchResp.getData().length);
NodeType idnt = (NodeType) searchResp.getData()[0];
assertElementIn(idnt.getElementId(), new String[] { "1" });
// test nothing found
searchText = "pacpac";
searchResp = dao.facetedSearch(NodeType.class, searchText, null, 10);
assertNotNull(searchResp);
assertNotNull(searchResp.getData());
assertNotNull(searchResp.getTypes());
assertEquals(0, searchResp.getData().length);
assertEquals(0, searchResp.getTypes().length);
}
use of alien4cloud.dao.model.FacetedSearchFacet in project alien4cloud by alien4cloud.
the class ESGenericSearchDAO method parseAggregations.
/**
* Parse aggregations and set facets to the given non null FacetedSearchResult instance.
*
* @param searchResponse The search response that contains aggregation results.
* @param facetedSearchResult The instance in which to set facets.
* @param aggregationQueryManager If not null the data of the FacetedSearchResult will be processed from an aggregation based on the given manager.
*/
private void parseAggregations(SearchResponse searchResponse, FacetedSearchResult facetedSearchResult, IAggregationQueryManager aggregationQueryManager) {
if (searchResponse.getAggregations() == null) {
return;
}
List<Aggregation> internalAggregationsList = searchResponse.getAggregations().asList();
if (internalAggregationsList.size() == 0) {
return;
}
Map<String, FacetedSearchFacet[]> facetMap = Maps.newHashMap();
for (Aggregation aggregation : internalAggregationsList) {
if (aggregationQueryManager != null && aggregation.getName().equals(aggregationQueryManager.getQueryAggregation().getName())) {
aggregationQueryManager.setData(getJsonMapper(), getClassFromTypeFunc(), facetedSearchResult, aggregation);
} else if (aggregation instanceof InternalTerms) {
InternalTerms internalTerms = (InternalTerms) aggregation;
List<FacetedSearchFacet> facets = new ArrayList<>();
for (int i = 0; i < internalTerms.getBuckets().size(); i++) {
Terms.Bucket bucket = internalTerms.getBuckets().get(i);
facets.add(new FacetedSearchFacet(bucket.getKey(), bucket.getDocCount()));
}
// Find the missing aggregation
internalAggregationsList.stream().filter(missingAggregation -> missingAggregation instanceof InternalMissing && missingAggregation.getName().equals("missing_" + internalTerms.getName())).findAny().ifPresent(missingAggregation -> {
InternalMissing internalMissingAggregation = (InternalMissing) missingAggregation;
if (internalMissingAggregation.getDocCount() > 0) {
facets.add(new FacetedSearchFacet(null, internalMissingAggregation.getDocCount()));
}
});
facetMap.put(internalTerms.getName(), facets.toArray(new FacetedSearchFacet[facets.size()]));
} else {
log.debug("Aggregation is not a facet aggregation (terms) ignore. Name: {} ,Type: {}", aggregation.getName(), aggregation.getClass().getName());
}
}
facetedSearchResult.setFacets(facetMap);
}
Aggregations