aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/juniper/queryvisitor.h
blob: def4b26480a860ca651dcc180f9a8fd6239e6f76 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "rpinterface.h"
#include "querynode.h"

// Juniper internal implementation of the IQueryVisitor interface as used by
// query providers (this is the initial 1.0.x structure implementation)

using QueryItem = juniper::QueryItem;
using IQuery = juniper::IQuery;
using QueryHandle = juniper::QueryHandle;

class Matcher;

namespace juniper {
    class QueryModifier;
}

/** See IQueryVisitor for detailed interface description
 */
class QueryVisitor : public juniper::IQueryVisitor
{
public:
    QueryVisitor(QueryVisitor &) = delete;
    QueryVisitor &operator=(QueryVisitor &) = delete;
    QueryVisitor(const IQuery& query, QueryHandle* qhandle, juniper::QueryModifier & queryModifier);
    ~QueryVisitor();

    bool VisitAND(const QueryItem* item, int arity) override;
    bool VisitOR(const QueryItem* item, int arity) override;
    bool VisitANY(const QueryItem* item, int arity) override;
    bool VisitNEAR(const QueryItem* item, int arity, int limit) override;
    bool VisitWITHIN(const QueryItem* item, int arity, int limit) override;
    bool VisitRANK(const QueryItem* item, int arity) override;
    bool VisitPHRASE(const QueryItem* item, int arity) override;
    bool VisitANDNOT(const QueryItem* item, int arity) override;
    bool VisitOther(const QueryItem* item, int arity) override;
    void VisitKeyword(const QueryItem* item, const char* keyword,
                      const size_t length = 0, bool prefix = false, bool specialToken = false) override;

    /** Grab pointer to (and ownership of) the query structure generated by this visitor.
     *  The call releases the query structure from this visitor.
     * @return The root node in the generated query tree now to be managed and
     *    subsequently deleted by caller
     */
    QueryExpr* GetQuery();

protected:
    std::string get_index(const QueryItem* item);
private:
    // Helper functions/members for use during construction only.
    void insert(QueryExpr* expr);
    void postprocess_query();
    juniper::QueryModifier & _queryModifier;

    const IQuery* _fquery; // Temp.pointer to the input query (valid in constructor only..

    // Members valid after init..
    QueryExpr* _query;  // Root of query
    QueryExpr* _current;  // Current position in query tree
    QueryHandle* _qhandle;
    int _term_index;
    bool _got_stack; // Set when we have created a stack root
};