use of com.agiletec.aps.system.common.tree.ITreeNode in project entando-core by entando.
the class SearcherDAO method createQuery.
protected Query createQuery(SearchEngineFilter[] filters, Collection<ITreeNode> categories, Collection<String> allowedGroups) {
BooleanQuery mainQuery = new BooleanQuery();
if (filters != null && filters.length > 0) {
for (int i = 0; i < filters.length; i++) {
SearchEngineFilter filter = filters[i];
Query fieldQuery = this.createQuery(filter);
mainQuery.add(fieldQuery, BooleanClause.Occur.MUST);
}
}
if (allowedGroups == null) {
allowedGroups = new HashSet<String>();
}
if (!allowedGroups.contains(Group.ADMINS_GROUP_NAME)) {
if (!allowedGroups.contains(Group.FREE_GROUP_NAME)) {
allowedGroups.add(Group.FREE_GROUP_NAME);
}
BooleanQuery groupsQuery = new BooleanQuery();
Iterator<String> iterGroups = allowedGroups.iterator();
while (iterGroups.hasNext()) {
String group = iterGroups.next();
TermQuery groupQuery = new TermQuery(new Term(IIndexerDAO.CONTENT_GROUP_FIELD_NAME, group));
groupsQuery.add(groupQuery, BooleanClause.Occur.SHOULD);
}
mainQuery.add(groupsQuery, BooleanClause.Occur.MUST);
}
if (null != categories && !categories.isEmpty()) {
BooleanQuery categoriesQuery = new BooleanQuery();
Iterator<ITreeNode> cateIter = categories.iterator();
while (cateIter.hasNext()) {
ITreeNode category = cateIter.next();
String path = category.getPath(IIndexerDAO.CONTENT_CATEGORY_SEPARATOR, false);
TermQuery categoryQuery = new TermQuery(new Term(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, path));
categoriesQuery.add(categoryQuery, BooleanClause.Occur.MUST);
}
mainQuery.add(categoriesQuery, BooleanClause.Occur.MUST);
}
return mainQuery;
}
Aggregations