Search in sources :

Example 61 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class NormalizingSearcherTestCase method createIndexFacts.

private IndexFacts createIndexFacts() {
    Map<String, List<String>> clusters = new LinkedHashMap<>();
    clusters.put("cluster1", Arrays.asList("type1", "type2", "type3"));
    clusters.put("cluster2", Arrays.asList("type4", "type5"));
    Map<String, SearchDefinition> searchDefs = new LinkedHashMap<>();
    searchDefs.put("type1", createSearchDefinitionWithFields("type1", true));
    searchDefs.put("type2", createSearchDefinitionWithFields("type2", false));
    searchDefs.put("type3", new SearchDefinition("type3"));
    searchDefs.put("type3", new SearchDefinition("type3"));
    searchDefs.put("type4", new SearchDefinition("type4"));
    searchDefs.put("type5", new SearchDefinition("type5"));
    SearchDefinition union = new SearchDefinition("union");
    return new IndexFacts(new IndexModel(clusters, searchDefs, union));
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) ArrayList(java.util.ArrayList) List(java.util.List) IndexModel(com.yahoo.prelude.IndexModel) LinkedHashMap(java.util.LinkedHashMap) SearchDefinition(com.yahoo.prelude.SearchDefinition)

Example 62 with IndexFacts

use of com.yahoo.prelude.IndexFacts 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 63 with IndexFacts

use of com.yahoo.prelude.IndexFacts 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)

Example 64 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class IndexFactsTestCase method testDefaultPosition.

@Test
public void testDefaultPosition() {
    Index a = new Index("a");
    assertFalse(a.isDefaultPosition());
    a.addCommand("any");
    assertFalse(a.isDefaultPosition());
    a.addCommand("default-position");
    assertTrue(a.isDefaultPosition());
    SearchDefinition sd = new SearchDefinition("sd");
    sd.addCommand("b", "any");
    assertNull(sd.getDefaultPosition());
    sd.addCommand("c", "default-position");
    assertTrue(sd.getDefaultPosition().equals("c"));
    SearchDefinition sd2 = new SearchDefinition("sd");
    sd2.addIndex(new Index("b").addCommand("any"));
    assertNull(sd2.getDefaultPosition());
    sd2.addIndex(a);
    assertTrue(sd2.getDefaultPosition().equals("a"));
    Map<String, SearchDefinition> m = new TreeMap<>();
    m.put(sd.getName(), sd);
    IndexFacts indexFacts = createIndexFacts();
    indexFacts.setSearchDefinitions(m, sd2);
    assertTrue(indexFacts.getDefaultPosition(null).equals("a"));
    assertTrue(indexFacts.getDefaultPosition("sd").equals("c"));
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Index(com.yahoo.prelude.Index) TreeMap(java.util.TreeMap) SearchDefinition(com.yahoo.prelude.SearchDefinition) Test(org.junit.Test)

Example 65 with IndexFacts

use of com.yahoo.prelude.IndexFacts in project vespa by vespa-engine.

the class IndexFactsTestCase method testUriIndexAndRestrict.

@Test
public void testUriIndexAndRestrict() {
    IndexInfoConfig.Builder b = new IndexInfoConfig.Builder();
    IndexInfoConfig.Indexinfo.Builder b1 = new IndexInfoConfig.Indexinfo.Builder();
    b1.name("hasUri");
    IndexInfoConfig.Indexinfo.Command.Builder bb1 = new IndexInfoConfig.Indexinfo.Command.Builder();
    bb1.indexname("url");
    bb1.command("fullurl");
    b1.command(bb1);
    b.indexinfo(b1);
    IndexInfoConfig.Indexinfo.Builder b2 = new IndexInfoConfig.Indexinfo.Builder();
    b2.name("hasNotUri1");
    b.indexinfo(b2);
    IndexInfoConfig.Indexinfo.Builder b3 = new IndexInfoConfig.Indexinfo.Builder();
    b3.name("hasNotUri2");
    b.indexinfo(b3);
    IndexInfoConfig config = new IndexInfoConfig(b);
    IndexFacts indexFacts = new IndexFacts(new IndexModel(config, Collections.emptyMap()));
    Query query1 = new Query("?query=url:https://foo.bar");
    Query query2 = new Query("?query=url:https://foo.bar&restrict=hasUri");
    assertEquals(0, query1.getModel().getRestrict().size());
    assertEquals(1, query2.getModel().getRestrict().size());
    IndexFacts.Session session1 = indexFacts.newSession(query1.getModel().getSources(), query1.getModel().getRestrict());
    IndexFacts.Session session2 = indexFacts.newSession(query2.getModel().getSources(), query2.getModel().getRestrict());
    assertTrue(session1.getIndex("url").isUriIndex());
    assertTrue(session2.getIndex("url").isUriIndex());
    assertEquals("url:\"https foo bar\"", query1.getModel().getQueryTree().toString());
    assertEquals("url:\"https foo bar\"", query2.getModel().getQueryTree().toString());
}
Also used : IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) Command(com.yahoo.search.config.IndexInfoConfig.Indexinfo.Command) Indexinfo(com.yahoo.search.config.IndexInfoConfig.Indexinfo) IndexInfoConfig(com.yahoo.search.config.IndexInfoConfig) IndexModel(com.yahoo.prelude.IndexModel) Test(org.junit.Test)

Aggregations

IndexFacts (com.yahoo.prelude.IndexFacts)73 Query (com.yahoo.search.Query)41 Execution (com.yahoo.search.searchchain.Execution)34 Test (org.junit.Test)26 Index (com.yahoo.prelude.Index)22 IndexModel (com.yahoo.prelude.IndexModel)12 Result (com.yahoo.search.Result)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)7 SearchDefinition (com.yahoo.prelude.SearchDefinition)6 IndexInfoConfig (com.yahoo.search.config.IndexInfoConfig)6 Chain (com.yahoo.component.chain.Chain)5 Token (com.yahoo.prelude.query.parser.Token)5 Tokenizer (com.yahoo.prelude.query.parser.Tokenizer)5 ConfigGetter (com.yahoo.config.subscription.ConfigGetter)4 AndItem (com.yahoo.prelude.query.AndItem)4 WordItem (com.yahoo.prelude.query.WordItem)4 HashSet (java.util.HashSet)4 LinkedHashMap (java.util.LinkedHashMap)4