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.CONTENT_ID_FIELD_NAME));
if (faceted) {
Set<String> codes = new HashSet<String>();
String[] categoryPaths = doc.getValues(IIndexerDAO.CONTENT_CATEGORY_FIELD_NAME);
for (int i = 0; i < categoryPaths.length; i++) {
String categoryPath = categoryPaths[i];
String[] paths = categoryPath.split(IIndexerDAO.CONTENT_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;
}
Aggregations