aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/searchdefinition/SummaryTestCase.java
blob: 6fbd80adaa9b8b88f5956874fe6b160be00481ac (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
package com.yahoo.searchdefinition;

import com.yahoo.searchdefinition.parser.ParseException;
import com.yahoo.vespa.model.test.utils.DeployLoggerStub;
import org.junit.Test;

import java.util.logging.Level;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * Tests summary validation
 *
 * @author bratseth
 */
public class SummaryTestCase {

    @Test
    public void testMemorySummary() throws ParseException {
        String sd =
                "search memorysummary {\n" +
                "\n" +
                "  document memorysummary {\n" +
                "\n" +
                "      field inmemory type string {\n" +
                "          indexing: attribute | summary\n" +
                "      }\n" +
                "      field ondisk type string {\n" +
                "          indexing: index # no summary, so ignored\n" +
                "      }\n" +
                "\n" +
                "  }\n" +
                "\n" +
                "}";
        DeployLoggerStub logger = new DeployLoggerStub();
        SearchBuilder.createFromString(sd, logger);
        assertTrue(logger.entries.isEmpty());
    }

    @Test
    public void testDiskSummary() throws ParseException {
        String sd =
                "search disksummary {\n" +
                "\n" +
                "  document-summary foobar {\n" +
                "      summary foo1 type string { source: inmemory }\n" +
                "      summary foo2 type string { source: ondisk }\n" +
                "  }\n" +
                "  document disksummary {\n" +
                "\n" +
                "      field inmemory type string {\n" +
                "          indexing: attribute | summary\n" +
                "      }\n" +
                "      field ondisk type string {\n" +
                "          indexing: index | summary\n" +
                "      }\n" +
                "\n" +
                "  }\n" +
                "\n" +
                "}";
        DeployLoggerStub logger = new DeployLoggerStub();
        SearchBuilder.createFromString(sd, logger);
        assertEquals(1, logger.entries.size());
        assertEquals(Level.WARNING, logger.entries.get(0).level);
        assertEquals("summary field 'foo2' in document summary 'foobar' references source field 'ondisk', " +
                     "which is not an attribute: Using this summary will cause disk accesses. " +
                     "Set 'from-disk' on this summary class to silence this warning.",
                     logger.entries.get(0).message);
    }

    @Test
    public void testDiskSummaryExplicit() throws ParseException {
        String sd =
                "search disksummary {\n" +
                "\n" +
                "  document disksummary {\n" +
                "\n" +
                "      field inmemory type string {\n" +
                "          indexing: attribute | summary\n" +
                "      }\n" +
                "      field ondisk type string {\n" +
                "          indexing: index | summary\n" +
                "      }\n" +
                "\n" +
                "  }\n" +
                "\n" +
                "  document-summary foobar {\n" +
                "      summary foo1 type string { source: inmemory }\n" +
                "      summary foo2 type string { source: ondisk }\n" +
                "      from-disk\n" +
                "  }\n" +
                "\n" +
                "}";
        DeployLoggerStub logger = new DeployLoggerStub();
        SearchBuilder.createFromString(sd, logger);
        assertTrue(logger.entries.isEmpty());
    }

    @Test
    public void testStructMemorySummary() throws ParseException {
        String sd =
                "search structmemorysummary {\n" +
                        "  document structmemorysummary {\n" +
                        "      struct elem {\n" +
                        "        field name type string {}\n" +
                        "        field weight type int {}\n" +
                        "      }\n" +
                        "      field elem_array type array<elem> {\n" +
                        "          indexing: summary\n" +
                        "          struct-field name {\n" +
                        "              indexing: attribute\n" +
                        "          }\n" +
                        "          struct-field weight {\n" +
                        "              indexing: attribute\n" +
                        "          }\n" +
                        "      }\n" +
                        "  }\n" +
                        "  document-summary filtered {\n" +
                        "      summary elem_array_filtered type array<elem> {\n" +
                        "          source: elem_array\n" +
                        "          matched-elements-only\n" +
                        "      }\n" +
                        "  }\n" +
                        "\n" +
                        "}";
        DeployLoggerStub logger = new DeployLoggerStub();
        SearchBuilder.createFromString(sd, logger);
        assertTrue(logger.entries.isEmpty());
    }

}