use of org.alfresco.rest.api.search.model.SearchEntry in project alfresco-remote-api by Alfresco.
the class ResultMapper method toCollectionWithPagingInfo.
/**
* Turns the results into a CollectionWithPagingInfo
* @param params
* @param searchQuery
*@param results @return CollectionWithPagingInfo<Node>
*/
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, SearchRequestContext searchRequestContext, SearchQuery searchQuery, ResultSet results) {
SearchContext context = null;
Integer total = null;
List<Node> noderesults = new ArrayList<Node>();
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
Map<NodeRef, List<Pair<String, List<String>>>> hightLighting = results.getHighlighting();
int notFound = 0;
boolean isHistory = searchRequestContext.getStores().contains(StoreMapper.HISTORY);
for (ResultSetRow row : results) {
Node aNode = getNode(row, params, mapUserInfo, isHistory);
if (aNode != null) {
float f = row.getScore();
List<HighlightEntry> highlightEntries = null;
List<Pair<String, List<String>>> high = hightLighting.get(row.getNodeRef());
if (high != null && !high.isEmpty()) {
highlightEntries = new ArrayList<HighlightEntry>(high.size());
for (Pair<String, List<String>> highlight : high) {
highlightEntries.add(new HighlightEntry(highlight.getFirst(), highlight.getSecond()));
}
}
aNode.setSearch(new SearchEntry(f, highlightEntries));
noderesults.add(aNode);
} else {
logger.debug("Unknown noderef returned from search results " + row.getNodeRef());
notFound++;
}
}
SolrJSONResultSet solrResultSet = findSolrResultSet(results);
if (solrResultSet != null) {
// We used Solr for this query
context = toSearchContext(solrResultSet, searchRequestContext, searchQuery, notFound);
total = setTotal(solrResultSet);
} else {
// This probably wasn't solr
if (!results.hasMore()) {
// If there are no more results then we are confident that the number found is correct
// otherwise we are not confident enough that its accurate
total = setTotal(results);
}
}
return CollectionWithPagingInfo.asPaged(params.getPaging(), noderesults, results.hasMore(), total, null, context);
}
Aggregations