Search in sources :

Example 1 with FacetedContentsResult

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

the class TestSearchEngineManager method testSearchFacetedContents_1.

public void testSearchFacetedContents_1() throws Throwable {
    try {
        Thread thread = this._searchEngineManager.startReloadContentsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this._searchEngineManager;
        Category general = this._categoryManager.getCategory("general");
        List<ITreeNode> categories = new ArrayList<ITreeNode>();
        categories.add(general);
        List<String> allowedGroup = new ArrayList<String>();
        allowedGroup.add(Group.FREE_GROUP_NAME);
        allowedGroup.add(Group.ADMINS_GROUP_NAME);
        FacetedContentsResult result = sem.searchFacetedEntities(null, categories, allowedGroup);
        assertNotNull(result);
        String[] expected1 = { "ART122", "ART102", "ART111", "ART120" };
        this.verify(result.getContentsId(), expected1);
        assertEquals(4, result.getOccurrences().size());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : FacetedContentsResult(org.entando.entando.aps.system.services.searchengine.FacetedContentsResult) Category(com.agiletec.aps.system.services.category.Category) ITreeNode(com.agiletec.aps.system.common.tree.ITreeNode) ArrayList(java.util.ArrayList)

Example 2 with FacetedContentsResult

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

the class TestSearchEngineManager method testFacetedAllContents.

public void testFacetedAllContents() throws Throwable {
    try {
        Thread thread = this._searchEngineManager.startReloadContentsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this._searchEngineManager;
        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) HashSet(java.util.HashSet)

Example 3 with FacetedContentsResult

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

the class TestSearchEngineManager method testSearchFacetedContents_1.

public void testSearchFacetedContents_1() throws Throwable {
    try {
        Thread thread = this.dataObjectSearchEngineManager.startReloadDataObjectsReferences();
        thread.join();
        SearchEngineManager sem = (SearchEngineManager) this.dataObjectSearchEngineManager;
        Category general = this._categoryManager.getCategory("general");
        List<ITreeNode> categories = new ArrayList<ITreeNode>();
        categories.add(general);
        List<String> allowedGroup = new ArrayList<String>();
        allowedGroup.add(Group.FREE_GROUP_NAME);
        allowedGroup.add(Group.ADMINS_GROUP_NAME);
        FacetedContentsResult result = sem.searchFacetedEntities(null, categories, allowedGroup);
        assertNotNull(result);
        String[] expected1 = { "ART122", "ART102", "ART111", "ART120" };
        this.verify(result.getContentsId(), expected1);
        assertEquals(4, result.getOccurrences().size());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : FacetedContentsResult(org.entando.entando.aps.system.services.searchengine.FacetedContentsResult) Category(com.agiletec.aps.system.services.category.Category) ITreeNode(com.agiletec.aps.system.common.tree.ITreeNode) IDataObjectSearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager) SearchEngineManager(org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager) ArrayList(java.util.ArrayList)

Example 4 with FacetedContentsResult

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

the class SearcherDAO method searchContents.

protected FacetedContentsResult searchContents(SearchEngineFilter[] filters, Collection<ITreeNode> categories, Collection<String> allowedGroups, boolean faceted) throws ApsSystemException {
    FacetedContentsResult result = new FacetedContentsResult();
    List<String> contentsId = new ArrayList<String>();
    IndexSearcher searcher = null;
    try {
        searcher = this.getSearcher();
        Query query = null;
        if ((null == filters || filters.length == 0) && (null == categories || categories.isEmpty()) && (allowedGroups != null && allowedGroups.contains(Group.ADMINS_GROUP_NAME))) {
            query = new MatchAllDocsQuery();
        } else {
            query = this.createQuery(filters, categories, allowedGroups);
        }
        TopDocs topDocs = searcher.search(query, null, 1000);
        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        Map<String, Integer> occurrences = new HashMap<String, Integer>();
        if (scoreDocs.length > 0) {
            for (int index = 0; index < scoreDocs.length; index++) {
                Document doc = searcher.doc(scoreDocs[index].doc);
                contentsId.add(doc.get(IIndexerDAO.DATAOBJECT_ID_FIELD_NAME));
                if (faceted) {
                    Set<String> codes = new HashSet<String>();
                    String[] categoryPaths = doc.getValues(IIndexerDAO.DATAOBJECT_CATEGORY_FIELD_NAME);
                    for (int i = 0; i < categoryPaths.length; i++) {
                        String categoryPath = categoryPaths[i];
                        String[] paths = categoryPath.split(IIndexerDAO.DATAOBJECT_CATEGORY_SEPARATOR);
                        codes.addAll(Arrays.asList(paths));
                    }
                    Iterator<String> iter = codes.iterator();
                    while (iter.hasNext()) {
                        String code = iter.next();
                        Integer value = occurrences.get(code);
                        if (null == value) {
                            value = 0;
                        }
                        occurrences.put(code, (value + 1));
                    }
                }
            }
        }
        result.setOccurrences(occurrences);
        result.setContentsId(contentsId);
    } catch (IndexNotFoundException inf) {
        _logger.error("no index was found in the Directory", inf);
    } catch (Throwable t) {
        _logger.error("Error extracting documents", t);
        throw new ApsSystemException("Error extracting documents", t);
    } finally {
        this.releaseResources(searcher);
    }
    return result;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) FacetedContentsResult(org.entando.entando.aps.system.services.searchengine.FacetedContentsResult) 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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) IndexNotFoundException(org.apache.lucene.index.IndexNotFoundException) HashSet(java.util.HashSet)

Example 5 with FacetedContentsResult

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

Aggregations

FacetedContentsResult (org.entando.entando.aps.system.services.searchengine.FacetedContentsResult)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 Category (com.agiletec.aps.system.services.category.Category)2 HashMap (java.util.HashMap)2 Document (org.apache.lucene.document.Document)2 IndexNotFoundException (org.apache.lucene.index.IndexNotFoundException)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 PhraseQuery (org.apache.lucene.search.PhraseQuery)2 Query (org.apache.lucene.search.Query)2 ScoreDoc (org.apache.lucene.search.ScoreDoc)2 TermQuery (org.apache.lucene.search.TermQuery)2 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)2 TopDocs (org.apache.lucene.search.TopDocs)2 IDataObjectSearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager)2 SearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager)2