Search in sources :

Example 1 with HighlightBuilderTests

use of org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilderTests in project elasticsearch by elastic.

the class InnerHitBuilderTests method mutate.

static InnerHitBuilder mutate(InnerHitBuilder original) throws IOException {
    final InnerHitBuilder copy = serializedCopy(original);
    List<Runnable> modifiers = new ArrayList<>(12);
    modifiers.add(() -> copy.setFrom(randomValueOtherThan(copy.getFrom(), () -> randomIntBetween(0, 128))));
    modifiers.add(() -> copy.setSize(randomValueOtherThan(copy.getSize(), () -> randomIntBetween(0, 128))));
    modifiers.add(() -> copy.setExplain(!copy.isExplain()));
    modifiers.add(() -> copy.setVersion(!copy.isVersion()));
    modifiers.add(() -> copy.setTrackScores(!copy.isTrackScores()));
    modifiers.add(() -> copy.setName(randomValueOtherThan(copy.getName(), () -> randomAsciiOfLengthBetween(1, 16))));
    modifiers.add(() -> {
        if (randomBoolean()) {
            copy.setDocValueFields(randomValueOtherThan(copy.getDocValueFields(), () -> {
                return randomListStuff(16, () -> randomAsciiOfLengthBetween(1, 16));
            }));
        } else {
            copy.addDocValueField(randomAsciiOfLengthBetween(1, 16));
        }
    });
    modifiers.add(() -> {
        if (randomBoolean()) {
            copy.setScriptFields(randomValueOtherThan(copy.getScriptFields(), () -> {
                return new HashSet<>(randomListStuff(16, InnerHitBuilderTests::randomScript));
            }));
        } else {
            SearchSourceBuilder.ScriptField script = randomScript();
            copy.addScriptField(script.fieldName(), script.script());
        }
    });
    modifiers.add(() -> copy.setFetchSourceContext(randomValueOtherThan(copy.getFetchSourceContext(), () -> {
        FetchSourceContext randomFetchSourceContext;
        if (randomBoolean()) {
            randomFetchSourceContext = new FetchSourceContext(randomBoolean());
        } else {
            randomFetchSourceContext = new FetchSourceContext(true, generateRandomStringArray(12, 16, false), generateRandomStringArray(12, 16, false));
        }
        return randomFetchSourceContext;
    })));
    modifiers.add(() -> {
        if (randomBoolean()) {
            final List<SortBuilder<?>> sortBuilders = randomValueOtherThan(copy.getSorts(), () -> {
                List<SortBuilder<?>> builders = randomListStuff(16, () -> SortBuilders.fieldSort(randomAsciiOfLengthBetween(5, 20)).order(randomFrom(SortOrder.values())));
                return builders;
            });
            copy.setSorts(sortBuilders);
        } else {
            copy.addSort(SortBuilders.fieldSort(randomAsciiOfLengthBetween(5, 20)));
        }
    });
    modifiers.add(() -> copy.setHighlightBuilder(randomValueOtherThan(copy.getHighlightBuilder(), HighlightBuilderTests::randomHighlighterBuilder)));
    modifiers.add(() -> {
        if (copy.getStoredFieldsContext() == null || randomBoolean()) {
            List<String> previous = copy.getStoredFieldsContext() == null ? Collections.emptyList() : copy.getStoredFieldsContext().fieldNames();
            List<String> newValues = randomValueOtherThan(previous, () -> randomListStuff(1, 16, () -> randomAsciiOfLengthBetween(1, 16)));
            copy.setStoredFieldNames(newValues);
        } else {
            copy.getStoredFieldsContext().addFieldName(randomAsciiOfLengthBetween(1, 16));
        }
    });
    randomFrom(modifiers).run();
    return copy;
}
Also used : SortBuilder(org.elasticsearch.search.sort.SortBuilder) ArrayList(java.util.ArrayList) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) HighlightBuilderTests(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilderTests) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext)

Aggregations

ArrayList (java.util.ArrayList)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1 FetchSourceContext (org.elasticsearch.search.fetch.subphase.FetchSourceContext)1 HighlightBuilderTests (org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilderTests)1 SortBuilder (org.elasticsearch.search.sort.SortBuilder)1