Skip to content

Commit

Permalink
Change type facet to drill down behavior
Browse files Browse the repository at this point in the history
- Show sub types if any type filter is active
- Apply active type filter to the aggregation

See #42
  • Loading branch information
fsteeg committed Mar 20, 2018
1 parent eb214ac commit 06e6b53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions app/modules/IndexComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.BoostingQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.node.Node;
Expand Down Expand Up @@ -197,17 +198,18 @@ private static void executeBulk(int pendingIndexRequests) {

@Override
public SearchResponse query(String q, String filter, int from, int size) {
BoostingQueryBuilder query = QueryBuilders.boostingQuery().negativeBoost(0.1f)
BoostingQueryBuilder boostQuery = QueryBuilders.boostingQuery().negativeBoost(0.1f)
.negative(QueryBuilders.matchQuery("type", "UndifferentiatedPerson"))
.positive(QueryBuilders.queryStringQuery(q).field("_all").field("preferredName", 0.5f)
.field("variantName", 0.1f).field("gndIdentifier", 0.5f));
BoolQueryBuilder query = QueryBuilders.boolQuery().must(boostQuery);
if (!filter.isEmpty()) {
query = query.filter(QueryBuilders.queryStringQuery(filter));
}
SearchRequestBuilder requestBuilder = client().prepareSearch(config("index.name")).setQuery(query).setFrom(from)
.setSize(size);
requestBuilder.addAggregation(
AggregationBuilders.terms(HomeController.TYPE).field(HomeController.TYPE + ".raw").size(1000));
if (!filter.isEmpty()) {
requestBuilder.setPostFilter(QueryBuilders.queryStringQuery(filter));
}
SearchResponse response = requestBuilder.get();
return response;
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/search.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

@links(buckets: Seq[JsValue], key: String) = {
@for(bucket <- buckets; term = (bucket \ "key").as[String];
if CONFIG.getStringList("topLevelTypes").contains(term);
if CONFIG.getStringList("topLevelTypes").contains(term) || f.contains("type:");
count = (bucket \ "doc_count").as[Int];
selected = f.contains(key+":"+term)) {
@if(!f.contains(key+":") || selected) {
Expand Down

0 comments on commit 06e6b53

Please sign in to comment.