aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/derived/CasedIndexTestCase.java
blob: 68a5a7b26dbfd6fa502544b41f912e8404154341 (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
package com.yahoo.schema.derived;

import com.yahoo.schema.ApplicationBuilder;
import com.yahoo.search.config.IndexInfoConfig;
import org.junit.jupiter.api.Test;

import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertFalse;

/**
 * @author bratseth
 */
public class CasedIndexTestCase {

    @Test
    public void testCasedIndexDeriving() throws Exception {
        var b = new ApplicationBuilder();
        b.addSchema("""
                    schema test {
                      document test {
                        field a type string {
                          indexing: summary | index
                          match: cased
                        }
                      }
                    }
                    """);
        var application = b.build(true);
        var config = new DerivedConfiguration(application.schemas().get("test"), b.getRankProfileRegistry());
        var indexInfo = config.getIndexInfo();
        var indexInfoConfigBuilder = new IndexInfoConfig.Builder();
        indexInfo.getConfig(indexInfoConfigBuilder);
        assertFalse(commandsOf("test", "a", indexInfoConfigBuilder).contains("lowercase"));
    }

    private Set<String> commandsOf(String schema, String field, IndexInfoConfig.Builder indexInfoConfigBuilder) {
        var schemaIndexInfo = indexInfoConfigBuilder.build().indexinfo().stream()
                                                    .filter(c -> c.name().equals(schema))
                                                    .findAny().get();
        return schemaIndexInfo.command().stream()
                              .filter(c -> c.indexname().equals(field))
                              .map(c -> c.command())
                              .collect(Collectors.toSet());
    }

}