use of org.alfresco.rest.api.search.model.HighlightEntry in project alfresco-remote-api by Alfresco.
the class ResultMapperTests method testToCollectionWithPagingInfo.
@Test
public void testToCollectionWithPagingInfo() throws Exception {
ResultSet results = mockResultset(Arrays.asList(514l), Arrays.asList(566l, VERSIONED_ID));
SearchRequestContext searchRequest = SearchRequestContext.from(SearchQuery.EMPTY);
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS, searchRequest, SearchQuery.EMPTY, results);
assertNotNull(collectionWithPage);
Long found = results.getNumberFound();
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
Node firstNode = collectionWithPage.getCollection().stream().findFirst().get();
assertNotNull(firstNode.getSearch().getScore());
assertEquals(StoreMapper.LIVE_NODES, firstNode.getLocation());
collectionWithPage.getCollection().stream().forEach(aNode -> {
List<HighlightEntry> high = aNode.getSearch().getHighlight();
if (high != null) {
assertEquals(2, high.size());
HighlightEntry first = high.get(0);
assertNotNull(first.getField());
assertNotNull(first.getSnippets());
}
});
// 1 deleted node in the test data
assertEquals(1l, collectionWithPage.getCollection().stream().filter(node -> StoreMapper.DELETED.equals(node.getLocation())).count());
// 1 version nodes in the test data (and 1 is not shown because it is in the archive store)
assertEquals(1l, collectionWithPage.getCollection().stream().filter(node -> StoreMapper.VERSIONS.equals(node.getLocation())).count());
}
use of org.alfresco.rest.api.search.model.HighlightEntry 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