aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/StemmingSettingTestCase.java
blob: e0f1f8dfa1cc758858c718f315ba5f1f9fe40286 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema;

import com.yahoo.schema.document.SDField;
import com.yahoo.schema.document.Stemming;
import com.yahoo.schema.parser.ParseException;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
 * Stemming settings test
 *
 * @author bratseth
 */
public class StemmingSettingTestCase extends AbstractSchemaTestCase {

    @Test
    void testStemmingSettings() throws IOException, ParseException {
        Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/stemmingsetting.sd");

        SDField artist = (SDField) schema.getDocument().getField("artist");
        assertEquals(Stemming.SHORTEST, artist.getStemming(schema));

        SDField title = (SDField) schema.getDocument().getField("title");
        assertEquals(Stemming.NONE, title.getStemming(schema));

        SDField song = (SDField) schema.getDocument().getField("song");
        assertEquals(Stemming.MULTIPLE, song.getStemming(schema));

        SDField track = (SDField) schema.getDocument().getField("track");
        assertEquals(Stemming.SHORTEST, track.getStemming(schema));

        SDField backward = (SDField) schema.getDocument().getField("backward");
        assertEquals(Stemming.SHORTEST, backward.getStemming(schema));

        Index defaultIndex = schema.getIndex("default");
        assertEquals(Stemming.SHORTEST, defaultIndex.getStemming());
    }

    @Test
    void requireThatStemmingIsDefaultBest() throws IOException, ParseException {
        Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/stemmingdefault.sd");
        assertNull(schema.getConcreteField("my_str").getStemming());
        assertEquals(Stemming.BEST, schema.getConcreteField("my_str").getStemming(schema));
    }

}