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;
}
}
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;
}
}
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;
}
}
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;
}
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;
}
}
Aggregations