aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/parsequery/stackdumpiterator.h
blob: 73c97bb5fb3179afd618922c3a15bcd530159910 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/parsequery/parse.h>
#include <vespa/searchlib/query/tree/predicate_query_term.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <vespa/vespalib/stllike/string.h>

namespace search {
/**
 * An iterator to be used on a buffer that is a stack dump
 * of a SimpleQueryStack.
 */
class SimpleQueryStackDumpIterator
{
private:
    SimpleQueryStackDumpIterator(const SimpleQueryStackDumpIterator &);
    SimpleQueryStackDumpIterator& operator=(const SimpleQueryStackDumpIterator &);

    /** Pointer to the start of the input buffer */
    const char *_buf;
    /** Pointer to just past the input buffer */
    const char *_bufEnd;
    /** Total length of the input buffer */
    size_t _bufLen;

    /** Pointer to the position of the current item in the buffer */
    const char *_currPos;
    /** Pointer to after the current item */
    const char *_currEnd;
    /** The type of the current item */
    ParseItem::ItemType _currType;
    ParseItem::ItemCreator _currCreator;
    /** Rank weight of current item **/
    query::Weight _currWeight;
    /** unique id of the current item **/
    uint32_t _currUniqueId;

    /** flags of the current item **/
    uint32_t _currFlags;

    /** The arity of the current item */
    uint32_t _currArity;

    /* extra arguments */
    uint32_t _extraIntArg1;
    uint32_t _extraIntArg2;
    uint32_t _extraIntArg3;
    double _extraDoubleArg4;
    double _extraDoubleArg5;
    /** The predicate query specification */
    query::PredicateQueryTerm::UP _predicate_query_term;
    /** The index name (field name) in the current item */
    vespalib::stringref _curr_index_name;
    /** The term in the current item */
    vespalib::stringref _curr_term;
    vespalib::asciistream _generatedTerm;

    vespalib::string readString(const char *&p);
    vespalib::stringref read_stringref(const char *&p);
    uint64_t readUint64(const char *&p);
    double read_double(const char *&p);
    uint64_t readCompressedPositiveInt(const char *&p);

public:
    /**
     * Make an iterator on a buffer. To get the first item, next
     * must be called.
     *
     * @param buf A pointer to the buffer holding the stackdump
     * @param buflen The length of the buffer in bytes
     */
    SimpleQueryStackDumpIterator(vespalib::stringref buf);
    ~SimpleQueryStackDumpIterator();

    vespalib::stringref getStack() const { return vespalib::stringref(_buf, _bufLen); }
    size_t getPosition() const { return _currPos - _buf; }

    /**
     * Moves to the next item in the buffer.
     *
     * @return true if there is a new item, false if there are no more items
     * or if there was errors in extracting the next item.
     */
    bool next();

    /**
     * Get the type of the current item.
     * @return the type.
     */
    ParseItem::ItemType getType() const { return _currType; }
    /**
     * Get the type of the current item.
     * @return the type.
     */
    ParseItem::ItemCreator getCreator() const { return _currCreator; }

    /**
     * Get the rank weight of the current item.
     *
     * @return rank weight.
     **/
    query::Weight GetWeight() const { return _currWeight; }

    /**
     * Get the unique id of the current item.
     *
     * @return unique id of current item
     **/
    uint32_t getUniqueId() const { return _currUniqueId; }

    /**
     * Get the flags of the current item.
     *
     * @return flags of current item
     **/
    uint32_t getFlags() const { return _currFlags; }

    uint32_t getArity() const { return _currArity; }

    uint32_t getNearDistance() const { return _extraIntArg1; }
    uint32_t getTargetNumHits() const { return _extraIntArg1; }
    double getScoreThreshold() const { return _extraDoubleArg4; }
    double getThresholdBoostFactor() const { return _extraDoubleArg5; }
    bool getAllowApproximate() const { return (_extraIntArg2 != 0); }
    uint32_t getExploreAdditionalHits() const { return _extraIntArg3; }

    query::PredicateQueryTerm::UP getPredicateQueryTerm()
    { return std::move(_predicate_query_term); }

    vespalib::stringref getIndexName() const { return _curr_index_name; }
    vespalib::stringref getTerm() const { return _curr_term; }
};

}