Search in sources :

Example 36 with ITreeNode

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;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) TermQuery(org.apache.lucene.search.TermQuery) ITreeNode(com.agiletec.aps.system.common.tree.ITreeNode) Query(org.apache.lucene.search.Query) PhraseQuery(org.apache.lucene.search.PhraseQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Term(org.apache.lucene.index.Term)

Aggregations

ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)36 Category (com.agiletec.aps.system.services.category.Category)9 ArrayList (java.util.ArrayList)9 PageTreeAction (com.agiletec.apsadmin.portal.PageTreeAction)7 IDataObjectSearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager)4 SearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager)4 SearchEngineFilter (org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)4 TreeNodeWrapper (com.agiletec.apsadmin.system.TreeNodeWrapper)2 Term (org.apache.lucene.index.Term)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 PhraseQuery (org.apache.lucene.search.PhraseQuery)2 Query (org.apache.lucene.search.Query)2 TermQuery (org.apache.lucene.search.TermQuery)2 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)2 FacetedContentsResult (org.entando.entando.aps.system.services.searchengine.FacetedContentsResult)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 IPage (com.agiletec.aps.system.services.page.IPage)1 IPageActionHelper (com.agiletec.apsadmin.portal.helper.IPageActionHelper)1 ValueStack (com.opensymphony.xwork2.util.ValueStack)1