summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/oktavia/test/test-search-result.jsx
blob: 81bcc05d06f7716ae8ef9f50bebd56a88702b838 (plain)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import "test-case.jsx";
import "search-result.jsx";


class _Test extends TestCase
{
    function test_simple_registration () : void
    {
        var result = new SingleResult();
        var section = result.getSearchUnit(0);
        section.addPosition('hello', 0, false);
        section.addPosition('world', 7, false);
        this.expect(section.size()).toBe(2);
    }

    function test_duplicate_longer_word_is_kept () : void
    {
        var result = new SingleResult();
        var section = result.getSearchUnit(0);
        section.addPosition('hello', 0, false);
        section.addPosition('hello world', 0, false);
        var position = section.get(0);

        this.expect(section.size()).toBe(1);
        this.expect(position.word).toBe('hello world');
    }

    function test_duplicate_no_stemmed_word_is_kept () : void
    {
        var result = new SingleResult();
        var section = result.getSearchUnit(0);
        section.addPosition('hello', 0, true);
        section.addPosition('hello', 0, false);
        var position = section.get(0);

        this.expect(section.size()).toBe(1);
        this.expect(position.stemmed).toBe(false);
    }

    function test_and_merge () : void
    {
        var result1 = new SingleResult();
        result1.getSearchUnit(0);
        result1.getSearchUnit(1);

        var result2 = new SingleResult();
        result2.getSearchUnit(0);

        var result3 = result1.merge(result2);

        this.expect(result3.size()).toBe(1);
    }

    function test_and_merge_2 () : void
    {
        var result1 = new SingleResult();
        result1.getSearchUnit(0);
        result1.getSearchUnit(1);

        var result2 = new SingleResult();
        result2.getSearchUnit(2);

        var result3 = result1.merge(result2);

        this.expect(result3.size()).toBe(0);
    }

    function test_or_merge () : void
    {
        var result1 = new SingleResult();
        result1.getSearchUnit(0);
        result1.getSearchUnit(1);

        var result2 = new SingleResult();
        result2.getSearchUnit(0);
        result2.getSearchUnit(2);
        result2.or = true;

        var result3 = result1.merge(result2);

        this.expect(result3.size()).toBe(3);
    }

    function test_not_merge () : void
    {
        var result1 = new SingleResult();
        result1.getSearchUnit(0);
        result1.getSearchUnit(1);
        result1.getSearchUnit(2);

        var result2 = new SingleResult();
        result2.getSearchUnit(0);
        result2.getSearchUnit(2);
        result2.not = true;

        var result3 = result1.merge(result2);

        this.expect(result3.size()).toBe(1);
    }

    function test_merge () : void
    {
        var summary = new SearchSummary();
        var singleresult1 = new SingleResult();
        singleresult1.getSearchUnit(0);
        singleresult1.getSearchUnit(1);

        var singleresult2 = new SingleResult();
        singleresult2.getSearchUnit(1);

        summary.add(singleresult1);
        summary.add(singleresult2);
        summary.mergeResult();

        this.expect(summary.size()).toBe(1);
    }

    function test_proposal () : void
    {
        var summary = new SearchSummary();
        var singleresult1 = new SingleResult();
        singleresult1.getSearchUnit(0);
        singleresult1.getSearchUnit(1);

        var singleresult2 = new SingleResult();
        singleresult2.getSearchUnit(2);

        summary.add(singleresult1);
        summary.add(singleresult2);

        var proposal = summary.getProposal();

        this.expect(proposal[0].omit).toBe(1);
        this.expect(proposal[0].expect).toBe(2);
        this.expect(proposal[1].omit).toBe(0);
        this.expect(proposal[1].expect).toBe(1);
    }

    function test_sort () : void
    {
        var summary = new SearchSummary();
        var singleresult = new SingleResult();
        var section1 = singleresult.getSearchUnit(0);
        var section2 = singleresult.getSearchUnit(1);
        var section3 = singleresult.getSearchUnit(2);

        summary.add(singleresult);
        summary.mergeResult();
        summary.result.getSearchUnit(0).score = 100;
        summary.result.getSearchUnit(1).score = 300;
        summary.result.getSearchUnit(2).score = 200;

        var result = summary.getSortedResult();
        this.expect(result.length).toBe(3);
        this.expect(result[0].id).toBe(1);
        this.expect(result[1].id).toBe(2);
        this.expect(result[2].id).toBe(0);
    }
}