|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +// score() over MATCH_PHRASE_PREFIX must not fail. When the terms the prefix expands to were rarer |
| 19 | +// than the other terms of the phrase, the union of them led the phrase and the scorer read its |
| 20 | +// norm, which threw "UnionTermIterator does not support scoring". |
| 21 | +suite("test_match_phrase_prefix_score", "p0") { |
| 22 | + sql "DROP TABLE IF EXISTS test_match_phrase_prefix_score_v2" |
| 23 | + sql "DROP TABLE IF EXISTS test_match_phrase_prefix_score_v3" |
| 24 | + |
| 25 | + sql """ |
| 26 | + CREATE TABLE test_match_phrase_prefix_score_v2 ( |
| 27 | + id INT NULL, |
| 28 | + c1 TEXT NULL, |
| 29 | + INDEX idx_c1 (c1) USING INVERTED PROPERTIES("lower_case" = "true", "parser" = "english", "support_phrase" = "true") |
| 30 | + ) ENGINE=OLAP |
| 31 | + DUPLICATE KEY(id) |
| 32 | + DISTRIBUTED BY HASH(id) BUCKETS 1 |
| 33 | + PROPERTIES ("replication_allocation" = "tag.location.default: 1", "inverted_index_storage_format" = "V2"); |
| 34 | + """ |
| 35 | + sql """ |
| 36 | + CREATE TABLE test_match_phrase_prefix_score_v3 ( |
| 37 | + id INT NULL, |
| 38 | + c1 TEXT NULL, |
| 39 | + INDEX idx_c1 (c1) USING INVERTED PROPERTIES("lower_case" = "true", "parser" = "english", "support_phrase" = "true") |
| 40 | + ) ENGINE=OLAP |
| 41 | + DUPLICATE KEY(id) |
| 42 | + DISTRIBUTED BY HASH(id) BUCKETS 1 |
| 43 | + PROPERTIES ("replication_allocation" = "tag.location.default: 1", "inverted_index_storage_format" = "V3"); |
| 44 | + """ |
| 45 | + |
| 46 | + // One insert per table keeps every table to a single segment. |
| 47 | + def rows = """(1, 'apple red'), (2, 'apple green'), (3, 'banana yellow'), (4, 'apple red green'), |
| 48 | + (5, 'apple apple red'), (6, 'red red red'), (7, 'apple gray'), (8, 'apple garden path')""" |
| 49 | + sql "INSERT INTO test_match_phrase_prefix_score_v2 VALUES ${rows}" |
| 50 | + sql "INSERT INTO test_match_phrase_prefix_score_v3 VALUES ${rows}" |
| 51 | + sql "sync" |
| 52 | + |
| 53 | + // 'apple r': the reported query, 'red' is rarer than 'apple'. |
| 54 | + order_qt_v2_apple_r """ SELECT id, round(score(), 4) s FROM test_match_phrase_prefix_score_v2 |
| 55 | + WHERE c1 MATCH_PHRASE_PREFIX 'apple r' ORDER BY score() DESC LIMIT 10 """ |
| 56 | + order_qt_v3_apple_r """ SELECT id, round(score(), 4) s FROM test_match_phrase_prefix_score_v3 |
| 57 | + WHERE c1 MATCH_PHRASE_PREFIX 'apple r' ORDER BY score() DESC LIMIT 10 """ |
| 58 | + |
| 59 | + // 'apple gr' expands to green and gray, both rarer than apple. |
| 60 | + order_qt_v2_apple_gr """ SELECT id, round(score(), 4) s FROM test_match_phrase_prefix_score_v2 |
| 61 | + WHERE c1 MATCH_PHRASE_PREFIX 'apple gr' ORDER BY score() DESC LIMIT 10 """ |
| 62 | + order_qt_v3_apple_gr """ SELECT id, round(score(), 4) s FROM test_match_phrase_prefix_score_v3 |
| 63 | + WHERE c1 MATCH_PHRASE_PREFIX 'apple gr' ORDER BY score() DESC LIMIT 10 """ |
| 64 | + |
| 65 | + // Two phrase terms before the prefix. |
| 66 | + order_qt_v2_apple_red_g """ SELECT id, round(score(), 4) s FROM test_match_phrase_prefix_score_v2 |
| 67 | + WHERE c1 MATCH_PHRASE_PREFIX 'apple red g' ORDER BY score() DESC LIMIT 10 """ |
| 68 | + order_qt_v3_apple_red_g """ SELECT id, round(score(), 4) s FROM test_match_phrase_prefix_score_v3 |
| 69 | + WHERE c1 MATCH_PHRASE_PREFIX 'apple red g' ORDER BY score() DESC LIMIT 10 """ |
| 70 | + |
| 71 | + // The same rows without score(). |
| 72 | + order_qt_v3_rows """ SELECT id FROM test_match_phrase_prefix_score_v3 |
| 73 | + WHERE c1 MATCH_PHRASE_PREFIX 'apple gr' """ |
| 74 | +} |
0 commit comments