Search in sources :

Example 31 with Index

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());
}
Also used : SimpleLinguistics(com.yahoo.language.simple.SimpleLinguistics) IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) Token(com.yahoo.prelude.query.parser.Token) Tokenizer(com.yahoo.prelude.query.parser.Tokenizer) Test(org.junit.Test)

Example 32 with Index

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;
}
Also used : Index(com.yahoo.prelude.Index) SearchDefinition(com.yahoo.prelude.SearchDefinition)

Example 33 with Index

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());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) Index(com.yahoo.prelude.Index) Test(org.junit.Test)

Example 34 with Index

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());
}
Also used : Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Index(com.yahoo.prelude.Index) Test(org.junit.Test)

Example 35 with Index

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());
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) Index(com.yahoo.prelude.Index) Test(org.junit.Test)

Aggregations

Index (com.yahoo.prelude.Index)36 IndexFacts (com.yahoo.prelude.IndexFacts)23 Test (org.junit.Test)13 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)7 Query (com.yahoo.search.Query)6 SearchDefinition (com.yahoo.prelude.SearchDefinition)5 Token (com.yahoo.prelude.query.parser.Token)5 Tokenizer (com.yahoo.prelude.query.parser.Tokenizer)5 Execution (com.yahoo.search.searchchain.Execution)4 JSONString (com.yahoo.prelude.hitfield.JSONString)2 XMLString (com.yahoo.prelude.hitfield.XMLString)2 CompositeItem (com.yahoo.prelude.query.CompositeItem)2 Hit (com.yahoo.search.result.Hit)2 List (java.util.List)2 Before (org.junit.Before)2 Chain (com.yahoo.component.chain.Chain)1 Language (com.yahoo.language.Language)1 StemMode (com.yahoo.language.process.StemMode)1 IndexModel (com.yahoo.prelude.IndexModel)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1