aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/juniper/rewriter.h
blob: 92542da5acc5c18dc0b39590d7dbba8c5f56ea8f (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/* $Id$ */

#pragma once

#include "query.h"

/** @file rewriter.h
 *  This file describes describes Juniper's expected interface for
 *  query word rewrite (typically language dependent)
 *  Rewrite of certain query words into a list of words
 *  are enabled by issuing an AddRewriter call.
 *
 *  The AddRewriter call is implemented by Juniper.
 *  The IRewriter interface must be implemented by the caller module
 *  to serve calls from juniper when the particular ItemCreator is found.
 *  Subsequent AddRewriter calls using the same ItemCreator will override
 *  the previous setting (rewrite and/or reduction for that creator.
 *  Multiple AddRewriter calls with different creator values are accepted.
 */

namespace juniper
{

// Opaque handle only used by implementer:
struct RewriteHandle;


class IRewriter
{
public:
    virtual ~IRewriter() {}

    /** return the name of this particular rewriter (for debugging purposes) */
    virtual const char* Name() const = 0;

    /** Map the given term to its rewritten form(s) wrt. the given language
     *  represented with language identifiers compatible with the
     *  ones used in the Analyse calls (rpinterface.h)
     *  @return a handle that can be used to retrieve words
     *  representing the rewritten forms. A NULL return value means
     *  that no rewrites exist and that the original form should be used.
     */
    virtual RewriteHandle* Rewrite(uint32_t langid, const char* term) = 0;
    virtual RewriteHandle* Rewrite(uint32_t langid, const char* term, size_t length) = 0;

    /** Retrieve the next term from the RewriteHandle object
     *  To be used repeatedly by Juniper until NULL is returned to
     *  signal that there are no more rewrites.
     *  At this point the RewriteHandle object and all the returned terms
     *  may become invalid. Juniper will either retrieve all terms returned
     *  by a Map call OR call the ReleaseHandle call:
     */
    virtual const char* NextTerm(RewriteHandle* exp, size_t& length) = 0;
};

} // end namespace juniper