Skip to content

Instantly share code, notes, and snippets.

@oak-tree
Last active January 4, 2016 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oak-tree/8664118 to your computer and use it in GitHub Desktop.
Save oak-tree/8664118 to your computer and use it in GitHub Desktop.
if (keywords.size() > 0) {
SetJoin<Report, Keyword> keyword = report.join(Report_.keywords);
Expression<Long> keywordExpr = keyword.get(Keyword_.id);
Predicate pred = keywordExpr.in(keywords);
preds.add(pred);
query.having(cb.equal(cb.countDistinct(keyword.get(Keyword_.id)),
keywords.size()));
}
if (tribes.size() > 0) {
SetJoin<Report, Tribe> item = report.join(Report_.tribes);
Expression<Long> itemExpr = item.get(Tribe_.id);
Predicate pred = itemExpr.in(tribes);
preds.add(pred);
query.having(cb.equal(cb.countDistinct(item.get(Tribe_.id)),
tribes.size()));
}
if (periods.size() > 0) {
SetJoin<Report, Period> item = report.join(Report_.periods);
Expression<Long> itemExpr = item.get(Period_.id);
Predicate pred = itemExpr.in(periods);
preds.add(pred);
query.having(cb.equal(cb.countDistinct(item.get(Period_.id)),
periods.size()));
}
query.where(cb.and(preds.toArray(new Predicate[preds.size()])))
.groupBy(report.get(Report_.id));
@oak-tree
Copy link
Author

if only one field is involved this result are ok. but when there are more than 1 field. i.e tribes and periods as well. the search can give on some input wrong results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment