Search in sources :

Example 11 with SearchEngineFilter

use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.

the class TestSearchEngineManager method testSearchAllContents.

public void testSearchAllContents() throws Throwable {
    try {
        Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
        thread.join();
        Set<String> allowedGroup = new HashSet<String>();
        SearchEngineFilter[] filters = {};
        SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
        List<String> freeContentsId = sem.searchEntityId(filters, null, allowedGroup);
        assertNotNull(freeContentsId);
        allowedGroup.add(Group.ADMINS_GROUP_NAME);
        List<String> allContentsId = sem.searchEntityId(filters, null, allowedGroup);
        assertNotNull(allContentsId);
        assertTrue(allContentsId.size() > freeContentsId.size());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) IDataObjectSearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager) SearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager) HashSet(java.util.HashSet)

Example 12 with SearchEngineFilter

use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.

the class TestSearchEngineManager method testFacetedAllContents.

public void testFacetedAllContents() throws Throwable {
    try {
        Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
        Set<String> allowedGroup = new HashSet<String>();
        allowedGroup.add(Group.ADMINS_GROUP_NAME);
        SearchEngineFilter[] filters = {};
        FacetedContentsResult result = sem.searchFacetedEntities(filters, null, allowedGroup);
        assertNotNull(result);
        assertNotNull(result.getContentsId());
        assertNotNull(result.getOccurrences());
        assertTrue(result.getContentsId().size() > 0);
        assertTrue(result.getOccurrences().size() > 0);
    } catch (Throwable t) {
        throw t;
    }
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) FacetedContentsResult(org.entando.entando.aps.system.services.searchengine.FacetedContentsResult) IDataObjectSearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager) SearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager) HashSet(java.util.HashSet)

Example 13 with SearchEngineFilter

use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.

the class SearchEngineManager method searchEntityId.

@Override
public List<String> searchEntityId(String langCode, String word, Collection<String> allowedGroups) throws ApsSystemException {
    SearchEngineFilter[] filters = new SearchEngineFilter[0];
    if (StringUtils.isNotEmpty(langCode) && StringUtils.isNotEmpty(word)) {
        SearchEngineFilter filter = new SearchEngineFilter(langCode, word);
        filter.setIncludeAttachments(true);
        filters = this.addFilter(filters, filter);
    }
    return this.searchEntityId(filters, null, allowedGroups);
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)

Example 14 with SearchEngineFilter

use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter 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)

Example 15 with SearchEngineFilter

use of org.entando.entando.aps.system.services.searchengine.SearchEngineFilter in project entando-core by entando.

the class UserFilterOptionBean method extractFilter.

public SearchEngineFilter extractFilter() {
    if (null == this.getFormFieldValues()) {
        return null;
    }
    SearchEngineFilter filter = null;
    String value0 = this.getFormValue(0);
    String value1 = this.getFormValue(1);
    if (!this.isAttributeFilter()) {
        if (this.getKey().equals(KEY_FULLTEXT) && !StringUtils.isEmpty(value0)) {
            // String[] fieldsSuffix = {"", "_option"};
            filter = new SearchEngineFilter(this.getCurrentLang().getCode(), value0, this.getOption(value1));
            String attachOption = this.getFormValue(2);
            try {
                filter.setIncludeAttachments(Boolean.parseBoolean(attachOption));
            } catch (Exception e) {
            }
        } else if (this.getKey().equals(KEY_CATEGORY) && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME, value0, SearchEngineFilter.TextSearchOption.EXACT);
        }
    } else {
        AttributeInterface attribute = this.getAttribute();
        if (attribute instanceof ITextAttribute && !StringUtils.isEmpty(value0)) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_textFieldName"};
        } else if (attribute instanceof DateAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            Date big0 = null;
            try {
                big0 = DateConverter.parseDate(value0, this.getDateFormat());
            } catch (Exception e) {
            }
            Date big1 = null;
            try {
                big1 = DateConverter.parseDate(value1, this.getDateFormat());
            } catch (Exception e) {
            }
            // String[] fieldsSuffix = {"_dateStartFieldName", "_dateEndFieldName"};
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        } else if (attribute instanceof BooleanAttribute && (!StringUtils.isEmpty(value0) && !StringUtils.isEmpty(value1))) {
            filter = new SearchEngineFilter(this.getIndexFieldName(), value0, SearchEngineFilter.TextSearchOption.EXACT);
        // String[] fieldsSuffix = {"_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control"};
        } else if (attribute instanceof NumberAttribute && (!StringUtils.isEmpty(value0) || !StringUtils.isEmpty(value1))) {
            // String[] fieldsSuffix = {"_numberStartFieldName", "_numberEndFieldName"};
            BigDecimal big0 = null;
            try {
                big0 = new BigDecimal(value0);
            } catch (Exception e) {
            }
            BigDecimal big1 = null;
            try {
                big1 = new BigDecimal(value1);
            } catch (Exception e) {
            }
            filter = new SearchEngineFilter(this.getIndexFieldName(), big0, big1);
        }
    }
    return filter;
}
Also used : SearchEngineFilter(org.entando.entando.aps.system.services.searchengine.SearchEngineFilter) ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) BooleanAttribute(com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) Date(java.util.Date) BigDecimal(java.math.BigDecimal) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Aggregations

SearchEngineFilter (org.entando.entando.aps.system.services.searchengine.SearchEngineFilter)15 ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Term (org.apache.lucene.index.Term)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 PhraseQuery (org.apache.lucene.search.PhraseQuery)4 TermQuery (org.apache.lucene.search.TermQuery)4 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)4 IDataObjectSearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager)4 SearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager)4 HashSet (java.util.HashSet)3 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)2 BooleanAttribute (com.agiletec.aps.system.common.entity.model.attribute.BooleanAttribute)2 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)2 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)2 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 Category (com.agiletec.aps.system.services.category.Category)2 BigDecimal (java.math.BigDecimal)2