summaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/searchsummary/docsummary/urlresult.h
blob: b076f82e4400fe8d2f197c495ec5b2bba45979ed (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Copyright (C) 2001-2003 Fast Search & Transfer ASA
// Copyright (C) 2003 Overture Services Norway AS

#pragma once

#include <vespa/searchsummary/docsummary/resultclass.h>
#include <vespa/searchsummary/docsummary/docsumstorevalue.h>

namespace search {
namespace docsummary {

class urlresult
{
protected:
    uint32_t _partition;
    uint32_t _docid;
    HitRank  _metric;

public:
    urlresult(uint32_t partition, uint32_t docid, HitRank metric);
    virtual ~urlresult();

    virtual bool IsGeneral() const { return false; }
    uint32_t GetPartition() const  { return _partition; }
    uint32_t GetDocID() const  { return _docid; }
    HitRank GetMetric() const { return _metric; }
    virtual int unpack(const char *buf, const size_t buflen) = 0;
};


class badurlresult : public urlresult
{
public:
    badurlresult();
    badurlresult(uint32_t partition, uint32_t docid, HitRank metric);
    virtual ~badurlresult();

    virtual int unpack(const char *buf, const size_t buflen) override;
};


class GeneralResult : public urlresult
{
private:
    GeneralResult(const GeneralResult &);
    GeneralResult& operator=(const GeneralResult &);

    const ResultClass      *_resClass;
    uint32_t                _entrycnt;
    ResEntry               *_entries;
    char                   *_buf;     // allocated in same chunk as _entries
    char                   *_bufEnd;  // first byte after _buf

    bool InBuf(void *pt)
    {
        return ((char *)pt >= _buf &&
                (char *)pt < _bufEnd);
    }

    void AllocEntries(uint32_t buflen, bool inplace = false);
    void FreeEntries();

    bool _inplace_unpack(const char *buf, const size_t buflen);

public:
    GeneralResult(const ResultClass *resClass, uint32_t partition,
                  uint32_t docid, HitRank metric);
    ~GeneralResult();

    const ResultClass *GetClass() const { return _resClass; }
    ResEntry *GetEntry(uint32_t idx);
    ResEntry *GetEntry(const char *name);
    ResEntry *GetEntryFromEnumValue(uint32_t val);
    virtual bool IsGeneral() const override { return true; }
    virtual int unpack(const char *buf, const size_t buflen) override;

    bool inplaceUnpack(const DocsumStoreValue &value) {
        if (value.valid()) {
	    return _inplace_unpack(value.fieldsPt(), value.fieldsSz());
        } else {
            return false;
        }
    }
};

}
}