Search in sources :

Example 1 with PageElement

use of com.yahoo.search.pagetemplates.model.PageElement in project vespa by vespa-engine.

the class ChoicesTestCase method testExecution.

@Test
public void testExecution() {
    // Create the page template (second alternative will be chosen)
    List<PageElement> pages = new ArrayList<>();
    pages.add(importPage("AnySource.xml"));
    pages.add(importPage("Choices.xml"));
    Choice page = Choice.createSingletons(pages);
    // Create a federated result
    Query query = new Query();
    Result result = new Result(query);
    result.hits().add(createHits("news", 3));
    result.hits().add(createHits("web", 3));
    result.hits().add(createHits("blog", 3));
    result.hits().add(createHits("images", 3));
    // Resolve
    Resolver resolver = new DeterministicResolver();
    Resolution resolution = resolver.resolve(page, query, result);
    // Execute
    Organizer organizer = new Organizer();
    organizer.organize(page, resolution, result);
    // Check rendering
    assertRendered(result, "ChoicesResult.xml");
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Query(com.yahoo.search.Query) Resolver(com.yahoo.search.pagetemplates.engine.Resolver) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Organizer(com.yahoo.search.pagetemplates.engine.Organizer) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) ArrayList(java.util.ArrayList) PageElement(com.yahoo.search.pagetemplates.model.PageElement) Result(com.yahoo.search.Result) Resolution(com.yahoo.search.pagetemplates.engine.Resolution) Test(org.junit.Test)

Example 2 with PageElement

use of com.yahoo.search.pagetemplates.model.PageElement in project vespa by vespa-engine.

the class PageTemplateSearcherTestCase method createPageTemplateRegistry.

private PageTemplateRegistry createPageTemplateRegistry() {
    PageTemplateRegistry registry = new PageTemplateRegistry();
    PageTemplate twoSources = new PageTemplate(new ComponentId("default"));
    twoSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    twoSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    registry.register(twoSources);
    PageTemplate oneSource = new PageTemplate(new ComponentId("oneSource"));
    oneSource.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    registry.register(oneSource);
    PageTemplate threeSources = new PageTemplate(new ComponentId("threeSources"));
    threeSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    threeSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    threeSources.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source3"));
    registry.register(threeSources);
    PageTemplate twoSourcesAndAny = new PageTemplate(new ComponentId("twoSourcesAndAny"));
    twoSourcesAndAny.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    twoSourcesAndAny.getSection().elements().add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    twoSourcesAndAny.getSection().elements().add(com.yahoo.search.pagetemplates.model.Source.any);
    registry.register(twoSourcesAndAny);
    PageTemplate anySource = new PageTemplate(new ComponentId("anySource"));
    anySource.getSection().elements().add(com.yahoo.search.pagetemplates.model.Source.any);
    registry.register(anySource);
    PageTemplate choiceOfSources = new PageTemplate(new ComponentId("choiceOfSources"));
    List<PageElement> alternatives = new ArrayList<>();
    alternatives.add(new com.yahoo.search.pagetemplates.model.Source("source1"));
    alternatives.add(new com.yahoo.search.pagetemplates.model.Source("source2"));
    choiceOfSources.getSection().elements().add(Choice.createSingletons(alternatives));
    registry.register(choiceOfSources);
    registry.freeze();
    return registry;
}
Also used : PageTemplate(com.yahoo.search.pagetemplates.PageTemplate) PageTemplateRegistry(com.yahoo.search.pagetemplates.PageTemplateRegistry) com.yahoo.search.intent.model(com.yahoo.search.intent.model) PageElement(com.yahoo.search.pagetemplates.model.PageElement) ComponentId(com.yahoo.component.ComponentId)

Example 3 with PageElement

use of com.yahoo.search.pagetemplates.model.PageElement in project vespa by vespa-engine.

the class PageTemplateSearcher method selectPageTemplates.

/**
 * Returns the list of page templates specified in the query, or the default if none, or the
 * empty list if no default, never null.
 */
private List<PageElement> selectPageTemplates(Query query) {
    // Determine the list of page template ids
    @SuppressWarnings("unchecked") List<String> pageIds = (List<String>) query.properties().get(pageIdListName);
    if (pageIds == null) {
        String pageIdString = query.properties().getString(pageIdName, "").trim();
        if (pageIdString.length() > 0)
            pageIds = Arrays.asList(pageIdString.split(" "));
    }
    // If none set, just return the default or null if none
    if (pageIds == null) {
        PageElement defaultPage = templateRegistry.getComponent("default");
        return (defaultPage == null ? Collections.<PageElement>emptyList() : Collections.singletonList(defaultPage));
    }
    // Resolve the id list to page templates
    List<PageElement> pages = new ArrayList<>(pageIds.size());
    for (String pageId : pageIds) {
        PageTemplate page = templateRegistry.getComponent(pageId);
        if (page == null)
            query.errors().add(ErrorMessage.createInvalidQueryParameter("Could not resolve requested page template '" + pageId + "'"));
        else
            pages.add(page);
    }
    return pages;
}
Also used : PageElement(com.yahoo.search.pagetemplates.model.PageElement)

Example 4 with PageElement

use of com.yahoo.search.pagetemplates.model.PageElement in project vespa by vespa-engine.

the class PageTemplateSearcher method search.

@Override
public Result search(Query query, Execution execution) {
    // Pre execution: Choose template and sources
    List<PageElement> pages = selectPageTemplates(query);
    // Bypass if no page template chosen
    if (pages.isEmpty())
        return execution.search(query);
    addSources(pages, query);
    // Set the page template list for inspection by other searchers
    query.properties().set(pagePageTemplateListName, pages);
    // Execute
    Result result = execution.search(query);
    // Post execution: Resolve choices and organize the result as dictated by the resolved template
    Choice pageTemplateChoice = Choice.createSingletons(pages);
    Resolution resolution = selectResolver(query).resolve(pageTemplateChoice, query, result);
    organizer.organize(pageTemplateChoice, resolution, result);
    return result;
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) PageElement(com.yahoo.search.pagetemplates.model.PageElement) Result(com.yahoo.search.Result) Resolution(com.yahoo.search.pagetemplates.engine.Resolution)

Example 5 with PageElement

use of com.yahoo.search.pagetemplates.model.PageElement in project vespa by vespa-engine.

the class PageTemplateSearcher method addSources.

/**
 * Sets query.getModel().getSources() to the right value and add source parameters specified in templates
 */
private void addSources(List<PageElement> pages, Query query) {
    // Determine all wanted sources
    Set<Source> pageSources = new HashSet<>();
    for (PageElement page : pages) pageSources.addAll(((PageTemplate) page).getSources());
    addErrorIfSameSourceMultipleTimes(pages, pageSources, query);
    if (query.getModel().getSources().size() > 0) {
        // Add properties if the source list is set explicitly, but do not modify otherwise
        addParametersForIncludedSources(pageSources, query);
        return;
    }
    if (pageSources.contains(Source.any)) {
        IntentModel intentModel = IntentModel.getFrom(query);
        if (intentModel != null) {
            query.getModel().getSources().addAll(intentModel.getSourceNames());
            addPageTemplateSources(pageSources, query);
        }
    // otherwise leave empty to search all
    } else {
        // Let the page templates decide
        addPageTemplateSources(pageSources, query);
    }
}
Also used : IntentModel(com.yahoo.search.intent.model.IntentModel) PageElement(com.yahoo.search.pagetemplates.model.PageElement) Source(com.yahoo.search.pagetemplates.model.Source)

Aggregations

PageElement (com.yahoo.search.pagetemplates.model.PageElement)5 Result (com.yahoo.search.Result)2 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)2 Choice (com.yahoo.search.pagetemplates.model.Choice)2 ComponentId (com.yahoo.component.ComponentId)1 Query (com.yahoo.search.Query)1 com.yahoo.search.intent.model (com.yahoo.search.intent.model)1 IntentModel (com.yahoo.search.intent.model.IntentModel)1 PageTemplate (com.yahoo.search.pagetemplates.PageTemplate)1 PageTemplateRegistry (com.yahoo.search.pagetemplates.PageTemplateRegistry)1 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)1 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)1 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)1 Source (com.yahoo.search.pagetemplates.model.Source)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1