aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/hitfield/AnnotateStringFieldPart.java
blob: 06d181281694b3da1bb2bb8f2914dd3e7919d9a6 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.hitfield;

public class AnnotateStringFieldPart implements FieldPart {

    public static final char RAW_ANNOTATE_BEGIN_CHAR = '\uFFF9';
    public static final char RAW_ANNOTATE_SEPARATOR_CHAR = '\uFFFA';
    public static final char RAW_ANNOTATE_END_CHAR = '\uFFFB';

    private String content;
    private String rawContent;

    public AnnotateStringFieldPart(String source, int index) {
        content = "";
        rawContent = "";
        if (source.charAt(index) == RAW_ANNOTATE_BEGIN_CHAR) {
            int sep = source.indexOf(RAW_ANNOTATE_SEPARATOR_CHAR, index);
            int end = source.indexOf(RAW_ANNOTATE_END_CHAR, index);

            if (sep != -1) {
                rawContent = source.substring(index + 1, sep);
                if (end != -1 && end > sep) {
                    content = source.substring(sep + 1, end);
                }
                else {
                    content = rawContent;
                }
            }
        }
    }

    public boolean isFinal() { return false; }

    public boolean isToken() { return true; }

    public String getContent() { return rawContent; }

    public void setContent(String content) {
        this.content = content;
    }

    public String toString() { return content; }

}