Search in sources :

Example 1 with SearchEntry

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);
}
Also used : HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) ArrayList(java.util.ArrayList) SearchContext(org.alfresco.rest.api.search.context.SearchContext) UserInfo(org.alfresco.rest.api.model.UserInfo) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) NodeRef(org.alfresco.service.cmr.repository.NodeRef) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) SearchEntry(org.alfresco.rest.api.search.model.SearchEntry) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) Pair(org.alfresco.util.Pair)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)1 Node (org.alfresco.rest.api.model.Node)1 UserInfo (org.alfresco.rest.api.model.UserInfo)1 SearchContext (org.alfresco.rest.api.search.context.SearchContext)1 HighlightEntry (org.alfresco.rest.api.search.model.HighlightEntry)1 SearchEntry (org.alfresco.rest.api.search.model.SearchEntry)1 TupleList (org.alfresco.rest.api.search.model.TupleList)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 ResultSetRow (org.alfresco.service.cmr.search.ResultSetRow)1 Pair (org.alfresco.util.Pair)1