@Override
    public Result search(Query query, Execution execution) {
        var ranking = query.getRanking();
        var rankProfileName = query.getRanking().getProfile();

        Optional<Boolean> useSignificanceModelOverride = ranking.getSignificance().getUseModel();

        if (useSignificanceModelOverride.isPresent() && !useSignificanceModelOverride.get()) {
            return execution.search(query);
        }
        if (useSignificanceModelOverride.isPresent()) {
            return calculateAndSetSignificance(query, execution);
        }
        // Determine significance setup per schema for the given rank profile
        var perSchemaSetup = schemaInfo.newSession(query).schemas().stream()
                .collect(Collectors.toMap(Schema::name, schema ->
                        // Fallback to disabled if the rank profile is not found in the schema
                        // This will result in a failure later (in a "backend searcher") anyway.
                        Optional.ofNullable(schema.rankProfiles().get(rankProfileName))
                                .map(RankProfile::useSignificanceModel).orElse(false)));
        log.log(Level.FINE, () -> "Significance setup per schema: " + perSchemaSetup);
        var uniqueSetups = new HashSet<>(perSchemaSetup.values());

        // Fail if the significance setup for the selected schemas are conflicting
        if (uniqueSetups.size() > 1) {
            var result = new Result(query);
            result.hits().addError(
                    ErrorMessage.createIllegalQuery(
                            ("Inconsistent 'significance' configuration for the rank profile '%s' in the schemas %s. " +
                                    "Use 'restrict' to limit the query to a subset of schemas " +
                                    "(https://docs.vespa.ai/en/schemas.html#multiple-schemas). " +
                                    "Specify same 'significance' configuration for all selected schemas " +
                                    "(https://docs.vespa.ai/en/reference/schema-reference.html#significance).")
                                    .formatted(rankProfileName, perSchemaSetup.keySet())));
            return result;
        }

        if (perSchemaSetup.isEmpty()) return execution.search(query);
        var useSignificanceModel = uniqueSetups.iterator().next();
        if (!useSignificanceModel) return execution.search(query);

        return calculateAndSetSignificance(query, execution);
    }
Sets significance values on word items in the query tree.

@author Marius Arhaug
container-search/src/main/java/com/yahoo/search/significance/SignificanceSearcher.java