blob: 9b216331551f71df9965fc70084b2d1680f895c3 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.query.parser.test;
import com.yahoo.prelude.Index;
import com.yahoo.prelude.IndexFacts;
import com.yahoo.search.Query;
import com.yahoo.search.searchchain.Execution;
import com.yahoo.search.test.QueryTestCase;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Check default index propagates correctly to the tokenizer.
*
* @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
*/
public class ExactMatchAndDefaultIndexTestCase extends junit.framework.TestCase {
public ExactMatchAndDefaultIndexTestCase(String name) {
super(name);
}
public void testExactMatchTokenization() {
Index index = new Index("testexact");
index.setExact(true, null);
IndexFacts facts = new IndexFacts();
facts.addIndex("testsd", index);
Query q = new Query("?query=" + enc("a/b foo.com") + "&default-index=testexact");
q.getModel().setExecution(new Execution(new Execution.Context(null, facts, null, null, null)));
assertEquals("AND testexact:a/b testexact:foo.com", q.getModel().getQueryTree().getRoot().toString());
q = new Query("?query=" + enc("a/b foo.com"));
assertEquals("AND \"a b\" \"foo com\"", q.getModel().getQueryTree().getRoot().toString());
}
// From Flickr, which had problems with this as they didn't use a default-index
// (query is dog & cat)
public void testDefaultIndexSpecialChars() {
Query q = new Query("?query=" + enc("dog & cat") + "&default-index=textsearch");
assertEquals("AND textsearch:dog textsearch:cat", q.getModel().getQueryTree().getRoot().toString());
}
private String enc(String s) {
try {
return URLEncoder.encode(s, "utf-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
|