aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/grouping/groupingmanager.h
blob: c8b25ba7bf47c21a2e6adceed4e14e687f720ba0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/searchlib/common/idocumentmetastore.h>
#include <vespa/searchcommon/attribute/iattributecontext.h>

namespace search {
    struct RankedHit;
    class BitVector;
}

namespace search::grouping {

class GroupingContext;

/**
 * Wrapper class used to handle actual grouping. All input data is
 * assumed to be kept alive by the user.
 **/
class GroupingManager
{
private:
    GroupingContext         &_groupingContext;
public:
    GroupingManager(const GroupingManager &) = delete;
    GroupingManager &operator=(const GroupingManager &) = delete;
    /**
     * Create a new grouping manager.
     *
     * @param groupingContext Context to use for grouping
     **/
    GroupingManager(GroupingContext & groupingContext);

    /**
     * Release resources
     **/
    ~GroupingManager();

    /**
     * @return true if this manager is holding an empty grouping request.
     **/
    bool empty() const;

    /**
     * Initialize underlying context with attribute bindings.
     *
     * @param attrCtx attribute context
     **/
    void init(const attribute::IAttributeContext &attrCtx);

    /**
     * Perform actual grouping on the given results.
     * The results must be in relevance sort order.
     * Will only perform grouping that will not resort.
     *
     * @param searchResults the result set in array form
     * @param binSize size of search result array
     **/
    void groupInRelevanceOrder(const RankedHit *searchResults, uint32_t binSize);

    /**
     * Perform actual grouping on the given the results.
     * The results should be in fastest access order which is normally unsorted.
     * Will only perform grouping that actually will resort.
     *
     * @param searchResults the result set in array form
     * @param binSize size of search result array
     * @param overflow The unranked hits.
     **/
    void groupUnordered(const RankedHit *searchResults, uint32_t binSize, const BitVector * overflow);

    /**
     * Merge another grouping context into the underlying context of
     * this manager. Both contexts must have the same groupings in the
     * same order.
     *
     * @param ctx context to merge into the underlying context of this manager
     **/
    void merge(GroupingContext &ctx);

    /**
     * Called after merge has been called (possibly multiple times) to
     * prune unwanted information from the underlying grouping
     * context.
     **/
    void prune();

    /**
     * Perform converting from local to global document id on all hits
     * in the underlying grouping trees.
     *
     * @param metaStore the attribute used to map from lid to gid.
     **/
    void convertToGlobalId(const IDocumentMetaStore &metaStore);
};

}