use of org.opensearch.search.fetch.subphase.highlight.Highlighter in project OpenSearch by opensearch-project.
the class SearchModuleTests method testRegisterHighlighter.
public void testRegisterHighlighter() {
CustomHighlighter customHighlighter = new CustomHighlighter();
SearchModule module = new SearchModule(Settings.EMPTY, singletonList(new SearchPlugin() {
@Override
public Map<String, Highlighter> getHighlighters() {
return singletonMap("custom", customHighlighter);
}
}));
Map<String, Highlighter> highlighters = module.getHighlighters();
assertEquals(FastVectorHighlighter.class, highlighters.get("fvh").getClass());
assertEquals(PlainHighlighter.class, highlighters.get("plain").getClass());
assertEquals(UnifiedHighlighter.class, highlighters.get("unified").getClass());
assertSame(highlighters.get("custom"), customHighlighter);
}
use of org.opensearch.search.fetch.subphase.highlight.Highlighter in project OpenSearch by opensearch-project.
the class SearchModuleTests method testDoubleRegister.
public void testDoubleRegister() {
SearchPlugin registersDupeHighlighter = new SearchPlugin() {
@Override
public Map<String, Highlighter> getHighlighters() {
return singletonMap("plain", new PlainHighlighter());
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeHighlighter));
SearchPlugin registersDupeSuggester = new SearchPlugin() {
@Override
public List<SearchPlugin.SuggesterSpec<?>> getSuggesters() {
return singletonList(new SuggesterSpec<>(TermSuggestionBuilder.SUGGESTION_NAME, TermSuggestionBuilder::new, TermSuggestionBuilder::fromXContent, TermSuggestion::new));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeSuggester));
SearchPlugin registersDupeScoreFunction = new SearchPlugin() {
@Override
public List<ScoreFunctionSpec<?>> getScoreFunctions() {
return singletonList(new ScoreFunctionSpec<>(GaussDecayFunctionBuilder.NAME, GaussDecayFunctionBuilder::new, GaussDecayFunctionBuilder.PARSER));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeScoreFunction));
SearchPlugin registersDupeSignificanceHeuristic = new SearchPlugin() {
@Override
public List<SignificanceHeuristicSpec<?>> getSignificanceHeuristics() {
return singletonList(new SignificanceHeuristicSpec<>(ChiSquare.NAME, ChiSquare::new, ChiSquare.PARSER));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeSignificanceHeuristic));
SearchPlugin registersDupeMovAvgModel = new SearchPlugin() {
@Override
public List<SearchExtensionSpec<MovAvgModel, MovAvgModel.AbstractModelParser>> getMovingAverageModels() {
return singletonList(new SearchExtensionSpec<>(SimpleModel.NAME, SimpleModel::new, SimpleModel.PARSER));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeMovAvgModel));
SearchPlugin registersDupeFetchSubPhase = new SearchPlugin() {
@Override
public List<FetchSubPhase> getFetchSubPhases(FetchPhaseConstructionContext context) {
return singletonList(new ExplainPhase());
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeFetchSubPhase));
SearchPlugin registersDupeQuery = new SearchPlugin() {
@Override
public List<SearchPlugin.QuerySpec<?>> getQueries() {
return singletonList(new QuerySpec<>(TermQueryBuilder.NAME, TermQueryBuilder::new, TermQueryBuilder::fromXContent));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeQuery));
SearchPlugin registersDupeAggregation = new SearchPlugin() {
@Override
public List<AggregationSpec> getAggregations() {
return singletonList(new AggregationSpec(TermsAggregationBuilder.NAME, TermsAggregationBuilder::new, TermsAggregationBuilder.PARSER));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeAggregation));
SearchPlugin registersDupePipelineAggregation = new SearchPlugin() {
@Override
public List<PipelineAggregationSpec> getPipelineAggregations() {
return singletonList(new PipelineAggregationSpec(DerivativePipelineAggregationBuilder.NAME, DerivativePipelineAggregationBuilder::new, DerivativePipelineAggregator::new, DerivativePipelineAggregationBuilder::parse).addResultReader(InternalDerivative::new));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupePipelineAggregation));
SearchPlugin registersDupeRescorer = new SearchPlugin() {
@Override
public List<RescorerSpec<?>> getRescorers() {
return singletonList(new RescorerSpec<>(QueryRescorerBuilder.NAME, QueryRescorerBuilder::new, QueryRescorerBuilder::fromXContent));
}
};
expectThrows(IllegalArgumentException.class, registryForPlugin(registersDupeRescorer));
}
use of org.opensearch.search.fetch.subphase.highlight.Highlighter in project OpenSearch by opensearch-project.
the class SearchModule method setupHighlighters.
private Map<String, Highlighter> setupHighlighters(Settings settings, List<SearchPlugin> plugins) {
NamedRegistry<Highlighter> highlighters = new NamedRegistry<>("highlighter");
highlighters.register("fvh", new FastVectorHighlighter(settings));
highlighters.register("plain", new PlainHighlighter());
highlighters.register("unified", new UnifiedHighlighter());
highlighters.extractAndRegister(plugins, SearchPlugin::getHighlighters);
return unmodifiableMap(highlighters.getRegistry());
}
Aggregations