protected Map<String, AggregationBuilder> getFacets(QueryBuilder query, HashMap<String, FilterBuilder> filters) {
Map<String, AggregationBuilder> aggregations = new HashMap<String, AggregationBuilder>();
- BoolFilterBuilder langFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query));
+ BoolFilterBuilder langFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
if (filter.getKey() != RuleNormalizer.RuleField.LANGUAGE.field()) {
langFacetFilter.must(filter.getValue());
.size(10)
.minDocCount(1))));
- BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query));
+ BoolFilterBuilder tagsFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
if (filter.getKey() != RuleNormalizer.RuleField._TAGS.field()) {
tagsFacetFilter.must(filter.getValue());
.size(10)
.minDocCount(1))));
- BoolFilterBuilder repositoriesFacetFilter = FilterBuilders.boolFilter();// .must(FilterBuilders.queryFilter(query));
+ BoolFilterBuilder repositoriesFacetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
if (filter.getKey() != RuleNormalizer.RuleField.REPOSITORY.field()) {
repositoriesFacetFilter.must(filter.getValue());
Result result = index.search(query, new QueryOptions().setFacet(false));
assertThat(result.getFacets()).isEmpty();
+ // should not have any facet on non matching query!
+ result = index.search(new RuleQuery().setQueryText("aeiou"), new QueryOptions().setFacet(true));
+ assertThat(result.getFacets()).isEmpty();
+
// Repositories Facet is preset
result = index.search(query, new QueryOptions().setFacet(true));
assertThat(result.getFacets()).isNotNull();