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));
}
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());
}
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());
}
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"));
}
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());
}
Aggregations