use of com.yahoo.search.pagetemplates.PageTemplateSearcher in project vespa by vespa-engine.
the class PageTemplateSearcherTestCase method testSearcher.
public void testSearcher() {
PageTemplateSearcher s = new PageTemplateSearcher(createPageTemplateRegistry(), new FirstChoiceResolver());
Chain<Searcher> chain = new Chain<>(s, new MockFederator());
{
// No template specified, should use default
Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.resolver=native.deterministic"));
assertSources("source1 source2", result);
}
{
Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=oneSource&page.resolver=native.deterministic"));
assertSources("source1", result);
}
{
Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=twoSources&model.sources=source1&page.resolver=native.deterministic"));
assertSources("source1", result);
}
{
Query query = new Query("?query=foo&page.resolver=native.deterministic");
addIntentModelSpecifyingSource3(query);
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2", result);
}
{
Query query = new Query("?query=foo&page.id=twoSourcesAndAny&page.resolver=native.deterministic");
addIntentModelSpecifyingSource3(query);
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2 source3", result);
}
{
Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
addIntentModelSpecifyingSource3(query);
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source3", result);
}
{
Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertTrue(query.getModel().getSources().isEmpty());
assertNotNull(result.hits().get("source1"));
assertNotNull(result.hits().get("source2"));
assertNotNull(result.hits().get("source3"));
}
{
Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=native.deterministic");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2", "source2", result);
}
{
Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=test.firstChoice");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2", "source1", result);
}
{
// Specifying two templates, should pick the last
Query query = new Query("?query=foo&page.id=threeSources+oneSource&page.resolver=native.deterministic");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2 source3", "source1", result);
}
{
// Specifying two templates as a list, should override the page.id setting
Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
query.properties().set("page.idList", Arrays.asList("oneSource", "threeSources"));
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
assertSources("source1 source2 source3", "source1 source2 source3", result);
}
{
try {
Query query = new Query("?query=foo&page.id=oneSource+choiceOfSources&page.resolver=noneSuch");
new Execution(chain, Execution.Context.createContextStub()).search(query);
fail("Expected exception");
} catch (IllegalArgumentException e) {
assertEquals("No page template resolver 'noneSuch'", e.getMessage());
}
}
}
use of com.yahoo.search.pagetemplates.PageTemplateSearcher in project vespa by vespa-engine.
the class SourceParametersTestCase method testSourceParametersWithSourcesDeterminedByParameter.
public void testSourceParametersWithSourcesDeterminedByParameter() {
// Create the page template
PageTemplateRegistry pageTemplateRegistry = new PageTemplateRegistry();
PageTemplate page = importPage("SourceParameters.xml");
pageTemplateRegistry.register(page);
PageTemplateSearcher s = new PageTemplateSearcher(pageTemplateRegistry);
Query query = new Query("?query=foo&page.id=SourceParameters&model.sources=source1,source3&page.resolver=native.deterministic");
new Execution(s, Execution.Context.createContextStub()).search(query);
assertEquals("source1p1Value", query.properties().get("source.source1.p1"));
assertEquals("source1p1Value", query.properties().get("source.source1.p1"));
assertEquals("source3p1Value", query.properties().get("source.source3.p1"));
assertEquals("We get the correct number of parameters", 3, query.properties().listProperties("source").size());
}
use of com.yahoo.search.pagetemplates.PageTemplateSearcher in project vespa by vespa-engine.
the class SourceParametersTestCase method testSourceParametersWithSourcesDeterminedByTemplate.
public void testSourceParametersWithSourcesDeterminedByTemplate() {
// Create the page template
PageTemplateRegistry pageTemplateRegistry = new PageTemplateRegistry();
PageTemplate page = importPage("SourceParameters.xml");
pageTemplateRegistry.register(page);
PageTemplateSearcher s = new PageTemplateSearcher(pageTemplateRegistry);
Query query = new Query("?query=foo&page.id=SourceParameters&page.resolver=native.deterministic");
new Execution(s, Execution.Context.createContextStub()).search(query);
assertEquals("source1p1Value", query.properties().get("source.source1.p1"));
assertEquals("source1p1Value", query.properties().get("source.source1.p1"));
assertEquals("source2p1Value", query.properties().get("source.source2.p1"));
assertEquals("source2p3Value", query.properties().get("source.source2.p3"));
assertEquals("source3p1Value", query.properties().get("source.source3.p1"));
assertEquals("We get the correct number of parameters", 5, query.properties().listProperties("source").size());
}
Aggregations