Search in sources :

Example 51 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class QueryProfileXMLReader method createQueryProfileTypes.

public List<Element> createQueryProfileTypes(List<NamedReader> queryProfileTypeReaders, QueryProfileTypeRegistry registry) {
    List<Element> queryProfileTypeElements = new ArrayList<>(queryProfileTypeReaders.size());
    for (NamedReader reader : queryProfileTypeReaders) {
        Element root = XML.getDocument(reader).getDocumentElement();
        if (!root.getNodeName().equals("query-profile-type")) {
            throw new IllegalArgumentException("Root tag in '" + reader.getName() + "' must be 'query-profile-type', not '" + root.getNodeName() + "'");
        }
        String idString = root.getAttribute("id");
        if (idString == null || idString.equals(""))
            throw new IllegalArgumentException("'" + reader.getName() + "' has no 'id' attribute in the root element");
        ComponentId id = new ComponentId(idString);
        validateFileNameToId(reader.getName(), id, "query profile type");
        QueryProfileType type = new QueryProfileType(id);
        type.setMatchAsPath(XML.getChild(root, "match") != null);
        type.setStrict(XML.getChild(root, "strict") != null);
        registry.register(type);
        queryProfileTypeElements.add(root);
    }
    return queryProfileTypeElements;
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NamedReader(com.yahoo.io.reader.NamedReader) QueryProfileType(com.yahoo.search.query.profile.types.QueryProfileType) ComponentId(com.yahoo.component.ComponentId)

Example 52 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class DuplicateSourceTestCase method testDuplicateSource.

@Test
public void testDuplicateSource() {
    // Set up a single cluster and chain (chain1), containing a MockBackendSearcher and having 2 doc types (doc1, doc2)
    MockBackendSearcher mockBackendSearcher = new MockBackendSearcher();
    SearchChainRegistry searchChains = new SearchChainRegistry();
    searchChains.register(new Chain<>("chain1", mockBackendSearcher));
    IndexFacts indexFacts = new IndexFacts();
    Map<String, List<String>> clusters = new HashMap<>();
    clusters.put("chain1", ImmutableList.of("doc1", "doc2"));
    indexFacts.setClusters(clusters);
    SearchChainResolver resolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("chain1"), ImmutableList.of("doc1", "doc2")).build();
    FederationSearcher searcher = new FederationSearcher(new ComponentId("test"), resolver);
    Result result = searcher.search(new Query("?query=test&sources=doc1%2cdoc2"), new Execution(Execution.Context.createContextStub(searchChains, indexFacts)));
    assertNull(result.hits().getError());
    assertEquals(1, mockBackendSearcher.getInvocationCount());
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) IndexFacts(com.yahoo.prelude.IndexFacts) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 53 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class FederationSearcherTestCase method addChained.

private void addChained(final Searcher searcher, final String sourceName) {
    builder.target(new FederationConfig.Target.Builder().id(sourceName).searchChain(new FederationConfig.Target.SearchChain.Builder().searchChainId(sourceName).timeoutMillis(10000).useByDefault(true)));
    chainRegistry.register(new ComponentId(sourceName), createSearchChain(new ComponentId(sourceName), searcher));
}
Also used : SearchChain(com.yahoo.search.searchchain.SearchChain) FederationConfig(com.yahoo.search.federation.FederationConfig) ComponentId(com.yahoo.component.ComponentId)

Example 54 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class FederationSearcherTestCase method createMultiProviderFederationSearcher.

private FederationSearcher createMultiProviderFederationSearcher() {
    FederationOptions options = new FederationOptions();
    SearchChainResolver.Builder builder = new SearchChainResolver.Builder();
    ComponentId provider1 = new ComponentId("provider1");
    ComponentId provider2 = new ComponentId("provider2");
    ComponentId news = new ComponentId("news");
    builder.addSearchChain(provider1, options, Collections.<String>emptyList());
    builder.addSearchChain(provider2, options, Collections.<String>emptyList());
    builder.addSourceForProvider(news, provider1, provider1, true, options, Collections.<String>emptyList());
    builder.addSourceForProvider(news, provider2, provider2, false, options, Collections.<String>emptyList());
    return new FederationSearcher(new ComponentId("federation"), builder.build());
}
Also used : FederationOptions(com.yahoo.search.searchchain.model.federation.FederationOptions) FederationSearcher(com.yahoo.search.federation.FederationSearcher) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) ComponentId(com.yahoo.component.ComponentId)

Example 55 with ComponentId

use of com.yahoo.component.ComponentId in project vespa by vespa-engine.

the class ClusteredConnectionTestCase method testClustering.

public void testClustering() {
    Connection connection0 = new Connection("0");
    Connection connection1 = new Connection("1");
    Connection connection2 = new Connection("2");
    List<Connection> connections = new ArrayList<>();
    connections.add(connection0);
    connections.add(connection1);
    connections.add(connection2);
    MyBackend myBackend = new MyBackend(new ComponentId("test"), connections);
    Result r;
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals("from:2", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
    assertEquals("from:1", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    connection2.setInService(false);
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
    assertEquals("from:1", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    connection1.setInService(false);
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    connection0.setInService(false);
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals("Failed calling connection '2' in searcher 'test' for query 'NULL': Connection failed", r.hits().getError().getDetailedMessage());
    connection0.setInService(true);
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    connection1.setInService(true);
    connection2.setInService(true);
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals("from:2", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(2));
    assertEquals("from:1", r.hits().get(0).getId().stringValue());
    r = new Execution(myBackend, Execution.Context.createContextStub()).search(new SimpleQuery(3));
    assertEquals("from:0", r.hits().get(0).getId().stringValue());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) ArrayList(java.util.ArrayList) ComponentId(com.yahoo.component.ComponentId) Result(com.yahoo.search.Result)

Aggregations

ComponentId (com.yahoo.component.ComponentId)68 Test (org.junit.Test)25 Result (com.yahoo.search.Result)14 Query (com.yahoo.search.Query)13 Execution (com.yahoo.search.searchchain.Execution)13 ArrayList (java.util.ArrayList)10 Chain (com.yahoo.component.chain.Chain)8 Searcher (com.yahoo.search.Searcher)8 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)7 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)7 FederationSearcher (com.yahoo.search.federation.FederationSearcher)6 Hit (com.yahoo.search.result.Hit)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 DomBuilderTest (com.yahoo.config.model.builder.xml.test.DomBuilderTest)4 ChainsConfig (com.yahoo.container.core.ChainsConfig)4 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)4 FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)4 QueryProfileTypeRegistry (com.yahoo.search.query.profile.types.QueryProfileTypeRegistry)4 Component (com.yahoo.vespa.model.container.component.Component)4 HashMap (java.util.HashMap)4