aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java
blob: b047f7c3b12ddd4e016242b2e68ad2d6dee3d9af (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
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.rewrite.test;

import com.yahoo.search.*;
import com.yahoo.search.searchchain.*;
import com.yahoo.search.intent.model.*;
import com.yahoo.search.query.rewrite.*;
import com.yahoo.search.query.rewrite.rewriters.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

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

/**
 * Test Cases for MisspellRewriter
 *
 * @author Karen Lee
 */
public class MisspellRewriterTestCase {

    private QueryRewriteSearcherTestUtils utils;
    public final String REWRITER_NAME = MisspellRewriter.REWRITER_NAME;

    /**
     * Load the QueryRewriteSearcher and prepare the
     * execution object
     */
    @BeforeEach
    public void setUp() {
        MisspellRewriter searcher = new MisspellRewriter();
        Execution execution = QueryRewriteSearcherTestUtils.createExecutionObj(searcher);
        utils = new QueryRewriteSearcherTestUtils(execution);
    }

    /**
     * QSSRewrite and QSSSuggest are on
     * QLAS returns spell correction: qss_rw=0.9 qss_sugg=1.0
     */
    @Test
    void testQSSRewriteQSSSuggestWithRewrite() {
        IntentModel intentModel = new IntentModel(
                utils.createInterpretation("will smith rw", 0.9,
                        true, false),
                utils.createInterpretation("will smith sugg", 1.0,
                        false, true));

        utils.assertRewrittenQuery("?query=willl+smith&" +
                REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" +
                REWRITER_NAME + "." + RewriterConstants.QSS_SUGG + "=true",
                "query 'OR (WEAKAND(100) willl smith) (WEAKAND(100) will smith sugg)'",
                intentModel);
    }

    /**
     * QSSRewrite is on
     * QLAS returns spell correction: qss_rw=0.9 qss_rw=0.9 qss_sugg=1.0
     */
    @Test
    void testQSSRewriteWithRewrite() {
        IntentModel intentModel = new IntentModel(
                utils.createInterpretation("will smith rw1", 0.9,
                        true, false),
                utils.createInterpretation("will smith rw2", 0.9,
                        true, false),
                utils.createInterpretation("will smith sugg", 1.0,
                        false, true));

        utils.assertRewrittenQuery("?query=willl+smith&" +
                REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true",
                "query 'OR (WEAKAND(100) willl smith) (WEAKAND(100) will smith rw1)'",
                intentModel);
    }

    /**
     * QSSSuggest is on
     * QLAS returns spell correction: qss_rw=1.0 qss_sugg=0.9 qss_sugg=0.8
     */
    @Test
    void testQSSSuggWithRewrite() {
        IntentModel intentModel = new IntentModel(
                utils.createInterpretation("will smith rw", 1.0,
                        true, false),
                utils.createInterpretation("will smith sugg1", 0.9,
                        false, true),
                utils.createInterpretation("will smith sugg2", 0.8,
                        false, true));

        utils.assertRewrittenQuery("?query=willl+smith&" +
                REWRITER_NAME + "." + RewriterConstants.QSS_SUGG + "=true",
                "query 'OR (WEAKAND(100) willl smith) (WEAKAND(100) will smith sugg1)'",
                intentModel);
    }

    /**
     * QSSRewrite and QSSSuggest are off
     * QLAS returns spell correction: qss_rw=1.0 qss_sugg=1.0
     */
    @Test
    void testFeautureOffWithRewrite() {
        IntentModel intentModel = new IntentModel(
                utils.createInterpretation("will smith rw", 1.0,
                        true, false),
                utils.createInterpretation("will smith sugg", 1.0,
                        false, true));

        utils.assertRewrittenQuery("?query=willl+smith",
                "query 'WEAKAND(100) willl smith'",
                intentModel);
    }

    /**
     * QSSRewrite and QSSSuggest are on
     * QLAS returns no spell correction
     */
    @Test
    void testQSSRewriteQSSSuggWithoutRewrite() {
        IntentModel intentModel = new IntentModel(
                utils.createInterpretation("use diff query for testing", 1.0,
                        false, false),
                utils.createInterpretation("use diff query for testing", 1.0,
                        false, false));

        utils.assertRewrittenQuery("?query=will+smith&" +
                REWRITER_NAME + "." + RewriterConstants.QSS_RW + "=true&" +
                REWRITER_NAME + "." + RewriterConstants.QSS_SUGG + "=true",
                "query 'WEAKAND(100) will smith'",
                intentModel);
    }

    /**
     * IntentModel is null
     * It should throw exception
     */
    @Test
    void testNullIntentModelException() {
        try {
            RewriterUtils.getSpellCorrected(new Query("willl smith"), true, true);
            fail();
        } catch (RuntimeException e) {
        }
    }

}