aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/matching/search_session.h
blob: d044ce456beabf8970fcc8114c481056f3f57bfe (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "match_context.h"
#include <vespa/searchcore/proton/documentmetastore/i_document_meta_store_context.h>
#include <vespa/searchcore/proton/summaryengine/isearchhandler.h>
#include <vespa/vespalib/stllike/string.h>
#include <vespa/vespalib/util/time.h>
#include <memory>

namespace search::fef { class Properties; }

namespace proton::matching {

class MatchToolsFactory;
class MatchContext;

/**
 * Holds enough data to perform a GetDocSum request. Makes sure the
 * data is kept alive.
 */
class SearchSession {
public:
    struct OwnershipBundle {
        OwnershipBundle() noexcept;
        OwnershipBundle(MatchContext && matchContext, std::shared_ptr<const ISearchHandler> searchHandler) noexcept;
        OwnershipBundle(OwnershipBundle &&) noexcept = default;
        OwnershipBundle & operator = (OwnershipBundle &&) noexcept = delete;
        ~OwnershipBundle();
        // Note that SearchHandler must above the other members due to life time guarantees.
        std::shared_ptr<const ISearchHandler> search_handler;
        MatchContext context;
        std::unique_ptr<search::fef::Properties> feature_overrides;
        IDocumentMetaStoreContext::IReadGuard::SP readGuard;
    };
private:
    using SessionId = vespalib::string;

    SessionId             _session_id;
    vespalib::steady_time _create_time;
    vespalib::steady_time _time_of_doom;
    OwnershipBundle       _owned_objects;
    std::unique_ptr<MatchToolsFactory> _match_tools_factory;

public:
    using SP = std::shared_ptr<SearchSession>;

    SearchSession(const SessionId &id, vespalib::steady_time create_time, vespalib::steady_time time_of_doom,
                  std::unique_ptr<MatchToolsFactory> match_tools_factory, OwnershipBundle &&owned_objects);
    ~SearchSession();

    const SessionId &getSessionId() const { return _session_id; }
    void releaseEnumGuards();

    /**
     * Gets this session's create time.
     */
    vespalib::steady_time getCreateTime() const { return _create_time; }

    /**
     * Gets this session's timeout.
     */
    vespalib::steady_time getTimeOfDoom() const { return _time_of_doom; }

    MatchToolsFactory &getMatchToolsFactory() { return *_match_tools_factory; }
};

}