use of com.yahoo.prelude.Index in project vespa by vespa-engine.
the class TokenizerTestCase method testExactMatchTokenization.
@Test
public void testExactMatchTokenization() {
Index index1 = new Index("testexact1");
index1.setExact(true, null);
Index index2 = new Index("testexact2");
index2.setExact(true, "()/aa*::*&");
IndexFacts facts = new IndexFacts();
facts.addIndex("testsd", index1);
facts.addIndex("testsd", index2);
IndexFacts.Session session = facts.newSession(Collections.emptySet(), Collections.emptySet());
Tokenizer tokenizer = new Tokenizer(new SimpleLinguistics());
List<?> tokens = tokenizer.tokenize("normal a:b (normal testexact1:/,%#%&+-+ ) testexact2:ho_/&%&/()/aa*::*& b:c", "default", session);
// tokenizer.print();
assertEquals(new Token(WORD, "normal"), tokens.get(0));
assertEquals(new Token(SPACE, " "), tokens.get(1));
assertEquals(new Token(WORD, "a"), tokens.get(2));
assertEquals(new Token(COLON, ":"), tokens.get(3));
assertEquals(new Token(WORD, "b"), tokens.get(4));
assertEquals(new Token(SPACE, " "), tokens.get(5));
assertEquals(new Token(LBRACE, "("), tokens.get(6));
assertEquals(new Token(WORD, "normal"), tokens.get(7));
assertEquals(new Token(SPACE, " "), tokens.get(8));
assertEquals(new Token(WORD, "testexact1"), tokens.get(9));
assertEquals(new Token(COLON, ":"), tokens.get(10));
assertEquals(new Token(WORD, "/,%#%&+-+"), tokens.get(11));
assertEquals(new Token(SPACE, " "), tokens.get(12));
assertEquals(new Token(RBRACE, ")"), tokens.get(13));
assertEquals(new Token(SPACE, " "), tokens.get(14));
assertEquals(new Token(WORD, "testexact2"), tokens.get(15));
assertEquals(new Token(COLON, ":"), tokens.get(16));
assertEquals(new Token(WORD, "ho_/&%&/"), tokens.get(17));
assertEquals(new Token(SPACE, " "), tokens.get(18));
assertEquals(new Token(WORD, "b"), tokens.get(19));
assertEquals(new Token(COLON, ":"), tokens.get(20));
assertEquals(new Token(WORD, "c"), tokens.get(21));
assertTrue(((Token) tokens.get(11)).isSpecial());
assertFalse(((Token) tokens.get(15)).isSpecial());
assertTrue(((Token) tokens.get(17)).isSpecial());
}
use of com.yahoo.prelude.Index in project vespa by vespa-engine.
the class NormalizingSearcherTestCase method createSearchDefinitionWithFields.
private SearchDefinition createSearchDefinitionWithFields(String name, boolean normalize) {
SearchDefinition type = new SearchDefinition(name);
Index defaultIndex = new Index("default");
defaultIndex.setNormalize(normalize);
type.addIndex(defaultIndex);
Index absoluteIndex = new Index("absolute");
absoluteIndex.setNormalize(normalize);
type.addIndex(absoluteIndex);
Index normalizercheckIndex = new Index("normalizercheck");
normalizercheckIndex.setNormalize(normalize);
type.addIndex(normalizercheckIndex);
Index attributeIndex = new Index("attribute");
attributeIndex.setAttribute(true);
type.addIndex(attributeIndex);
return type;
}
use of com.yahoo.prelude.Index in project vespa by vespa-engine.
the class ExactMatchAndDefaultIndexTestCase method testExactMatchTokenization.
@Test
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());
}
use of com.yahoo.prelude.Index in project vespa by vespa-engine.
the class IndexFactsTestCase method testExactMatching.
@Test
public void testExactMatching() {
assertExactIsWorking("test");
assertExactIsWorking("artist_name_ft_norm1");
List search = new ArrayList();
search.add("three");
Query query = new Query();
query.getModel().getSources().add("three");
IndexFacts.Session threeSession = createIndexFacts().newSession(query);
IndexFacts.Session nullSession = createIndexFacts().newSession(new Query());
Index d3 = threeSession.getIndex("d");
assertTrue(d3.isExact());
assertEquals(" ", d3.getExactTerminator());
Index e = nullSession.getIndex("e");
assertTrue(e.isExact());
assertEquals("kj(/&", e.getExactTerminator());
Index a = nullSession.getIndex("a");
assertFalse(a.isExact());
assertNull(a.getExactTerminator());
Index wem = threeSession.getIndex("twewm");
assertTrue(wem.isExact());
assertNull(wem.getExactTerminator());
}
use of com.yahoo.prelude.Index in project vespa by vespa-engine.
the class IndexFactsTestCase method testComplexExactMatching.
@Test
public void testComplexExactMatching() {
IndexFacts indexFacts = createIndexFacts();
String u_name = "foo_bar";
Index u_index = new Index(u_name);
u_index.setExact(true, "^^^");
Index b_index = new Index("bar");
indexFacts.addIndex("foobar", u_index);
indexFacts.addIndex("foobar", b_index);
Query query = new Query();
query.getModel().getSources().add("foobar");
IndexFacts.Session session = indexFacts.newSession(query);
assertFalse(session.getIndex("bar").isExact());
assertTrue(session.getIndex(u_name).isExact());
Query q = newQuery("?query=" + u_name + ":foo...&search=foobar", indexFacts);
assertEquals(u_name + ":foo...", q.getModel().getQueryTree().getRoot().toString());
}
Aggregations