use of org.elasticsearch.index.query.BoolFilterBuilder in project stash-codesearch-plugin by palantir.
the class SearchFilterUtils method aclFilter.
public FilterBuilder aclFilter(Map<String, Repository> repoMap) {
if (repoMap.isEmpty()) {
return boolFilter().mustNot(matchAllFilter());
}
// Compute cryptographic hash of repository set to use for cache key
String[] projectRepoPairs = repoMap.keySet().toArray(new String[repoMap.size()]);
Arrays.sort(projectRepoPairs);
String filterHash;
try {
MessageDigest hasher = MessageDigest.getInstance("SHA-256");
for (String pair : projectRepoPairs) {
hasher.update(pair.getBytes());
hasher.update((byte) 0);
}
filterHash = new String(Base64.encodeBase64(hasher.digest()));
} catch (Exception e) {
filterHash = null;
log.error("Caught exception generating ACL hash -- caching is disabled.", e);
}
// Create disjunction of individual repo ACL filters
BoolFilterBuilder filter = boolFilter();
if (filterHash != null) {
filter.cache(true).cacheKey("CACHE^ACLORFILTER^" + filterHash);
} else {
filter.cache(false);
}
for (Repository repo : repoMap.values()) {
filter.should(projectRepositoryFilter(repo.getProject().getKey(), repo.getSlug()));
}
return filter;
}
Aggregations