summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/query/rewrite/test/MisspellRewriterTestCase.java
blob: 82f548727f687f6c2b0a88b364604bb420107aa4 (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
// Copyright 2017 Yahoo Holdings. 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.*;

/**
 * Test Cases for MisspellRewriter
 *
 * @author karenlee@yahoo-inc.com
 */
public class MisspellRewriterTestCase extends junit.framework.TestCase {

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

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

    public MisspellRewriterTestCase(String name) {
        super(name);
    }

    /**
     * QSSRewrite and QSSSuggest are on
     * QLAS returns spell correction: qss_rw=0.9 qss_sugg=1.0
     */
    public 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 (AND willl smith) (AND will smith sugg)'",
                                   intentModel);
    }

    /**
     * QSSRewrite is on
     * QLAS returns spell correction: qss_rw=0.9 qss_rw=0.9 qss_sugg=1.0
     */
    public 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 (AND willl smith) (AND will smith rw1)'",
                                   intentModel);
    }

    /**
     * QSSSuggest is on
     * QLAS returns spell correction: qss_rw=1.0 qss_sugg=0.9 qss_sugg=0.8
     */
    public 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 (AND willl smith) (AND will smith sugg1)'",
                                   intentModel);
    }

    /**
     * QSSRewrite and QSSSuggest are off
     * QLAS returns spell correction: qss_rw=1.0 qss_sugg=1.0
     */
    public 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 'AND willl smith'",
                                   intentModel);
    }

    /**
     * QSSRewrite and QSSSuggest are on
     * QLAS returns no spell correction
     */
    public 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 'AND will smith'",
                                   intentModel);
    }

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