aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/querytransform/VespaLowercasingSearcher.java
blob: 910cf5baa8719a298f75f9588ae4725d74b2ef7e (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.querytransform;

import static com.yahoo.prelude.querytransform.NormalizingSearcher.ACCENT_REMOVAL;
import static com.yahoo.prelude.querytransform.StemmingSearcher.STEMMING;

import java.util.Collection;

import com.yahoo.component.chain.dependencies.After;
import com.yahoo.component.chain.dependencies.Provides;
import com.yahoo.prelude.Index;
import com.yahoo.prelude.IndexFacts;
import com.yahoo.prelude.query.WordItem;

/**
 * Transform terms in query tree to lower case based on Vespa index settings.
 *
 * @author Steinar Knutsen
 */
@After({ STEMMING, ACCENT_REMOVAL })
@Provides(VespaLowercasingSearcher.LOWERCASING)
public class VespaLowercasingSearcher extends LowercasingSearcher {

    public static final String LOWERCASING = "LowerCasing";

    public VespaLowercasingSearcher(LowercasingConfig cfg) {
        super(cfg);
    }

    @Override
    public boolean shouldLowercase(WordItem word, IndexFacts.Session indexFacts) {
        if (word.isLowercased()) return false;

        return indexFacts.getIndex(word.getIndexName()).isLowercase();
    }

    @Override
    public boolean shouldLowercase(String commonPath, WordItem word, IndexFacts.Session indexFacts) {
        if (word.isLowercased()) return false;

        return indexFacts.getIndex(commonPath + "." + word.getIndexName()).isLowercase();
    }

}