@Override
    public Result search(Query query, Execution execution) {
        Result mergedResults = execution.search(query);

        var targets = getTargets(query.getModel().getSources(), query.properties());
        warnIfUnresolvedSearchChains(extractErrors(targets), mergedResults.hits());

        var prunedTargets = pruneTargetsWithoutDocumentTypes(query.getModel().getRestrict(), extractSpecs(targets));

        var regularTargetHandlers = resolveSearchChains(prunedTargets, execution.searchChainRegistry());
        query.errors().addAll(regularTargetHandlers.errors());

        Set<Target> targetHandlers = new LinkedHashSet<>(regularTargetHandlers.data());
        targetHandlers.addAll(getAdditionalTargets(query, execution, targetSelector));

        traceTargets(query, targetHandlers);

        if (targetHandlers.isEmpty())
            return mergedResults;
        else if (targetHandlers.size() > 1)
            search(query, execution, targetHandlers, mergedResults);
        else if (shouldExecuteTargetLongerThanThread(query, targetHandlers.iterator().next()))
            search(query, execution, targetHandlers, mergedResults); // one target, but search in separate thread
        else
            search(query, execution, first(targetHandlers), mergedResults); // search in this thread
        return mergedResults;
    }
@Test
    void target_selectors_can_have_multiple_targets() {
        ComponentId targetSelectorId = ComponentId.fromString("TestMultipleTargetSelector");
        ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
        targetSelectors.register(targetSelectorId, new TestMultipleTargetSelector());

        FederationSearcher searcher = new FederationSearcher(
                new FederationConfig(new FederationConfig.Builder().targetSelector(targetSelectorId.toString())),
                SchemaInfo.empty(),
                targetSelectors);

        Query query = new Query();
        query.setTimeout(20000);
        Result result = new Execution(searcher, Context.createContextStub()).search(query);

        Iterator<Hit> hitsIterator = result.hits().deepIterator();
        Hit hit1 = hitsIterator.next();
        Hit hit2 = hitsIterator.next();

        assertEquals(hit1.getSource(), "chain1");
        assertEquals(hit2.getSource(), "chain2");

        assertEquals(hit1.getField("data"), "modifyTargetQuery:custom-data:1");
        assertEquals(hit2.getField("data"), "modifyTargetQuery:custom-data:2");
    }