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

#include <vespa/vespalib/stllike/string.h>
#include <iosfwd>

namespace search {

enum class Normalizing : uint8_t {
    NONE,
    LOWERCASE,
    LOWERCASE_AND_FOLD
};

enum class TermType : uint8_t {
    WORD = 0,
    PREFIXTERM = 1,
    SUBSTRINGTERM = 2,
    EXACTSTRINGTERM = 3,
    SUFFIXTERM = 4,
    REGEXP = 5,
    GEO_LOCATION = 6,
    FUZZYTERM = 7,
    NEAREST_NEIGHBOR = 8
};

std::ostream &operator<<(std::ostream &, Normalizing);

/**
 * Resolves what kind of normalization that is needed for the query terms in context
 * of the fields searched. It also provides a utility method for doing the normalization.
 */
class QueryNormalization {
public:
    using Normalizing = search::Normalizing;
    virtual ~QueryNormalization() = default;
    virtual bool is_text_matching(vespalib::stringref index) const noexcept = 0;
    virtual Normalizing normalizing_mode(vespalib::stringref index) const noexcept = 0;
    static vespalib::string optional_fold(vespalib::stringref s, TermType type, Normalizing normalizing);
};

}