Search in sources :

Example 1 with Highlighter

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

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, () -> new SearchModule(Settings.EMPTY, false, singletonList(registersDupeHighlighter)));
    SearchPlugin registersDupeSuggester = new SearchPlugin() {

        public List<SearchPlugin.SuggesterSpec<?>> getSuggesters() {
            return singletonList(new SuggesterSpec<>("term", TermSuggestionBuilder::new, TermSuggestionBuilder::fromXContent));
        }
    };
    expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, singletonList(registersDupeSuggester)).getNamedXContents()));
    SearchPlugin registersDupeScoreFunction = new SearchPlugin() {

        @Override
        public List<ScoreFunctionSpec<?>> getScoreFunctions() {
            return singletonList(new ScoreFunctionSpec<>(GaussDecayFunctionBuilder.NAME, GaussDecayFunctionBuilder::new, GaussDecayFunctionBuilder.PARSER));
        }
    };
    expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, singletonList(registersDupeScoreFunction)).getNamedXContents()));
    SearchPlugin registersDupeSignificanceHeuristic = new SearchPlugin() {

        @Override
        public List<SearchExtensionSpec<SignificanceHeuristic, SignificanceHeuristicParser>> getSignificanceHeuristics() {
            return singletonList(new SearchExtensionSpec<>(ChiSquare.NAME, ChiSquare::new, ChiSquare.PARSER));
        }
    };
    expectThrows(IllegalArgumentException.class, () -> new SearchModule(Settings.EMPTY, false, singletonList(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, () -> new SearchModule(Settings.EMPTY, false, singletonList(registersDupeMovAvgModel)));
    SearchPlugin registersDupeFetchSubPhase = new SearchPlugin() {

        @Override
        public List<FetchSubPhase> getFetchSubPhases(FetchPhaseConstructionContext context) {
            return singletonList(new ExplainFetchSubPhase());
        }
    };
    expectThrows(IllegalArgumentException.class, () -> new SearchModule(Settings.EMPTY, false, singletonList(registersDupeFetchSubPhase)));
    SearchPlugin registersDupeQuery = new SearchPlugin() {

        public List<SearchPlugin.QuerySpec<?>> getQueries() {
            return singletonList(new QuerySpec<>(TermQueryBuilder.NAME, TermQueryBuilder::new, TermQueryBuilder::fromXContent));
        }
    };
    expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, singletonList(registersDupeQuery)).getNamedXContents()));
    SearchPlugin registersDupeAggregation = new SearchPlugin() {

        public List<AggregationSpec> getAggregations() {
            return singletonList(new AggregationSpec(TermsAggregationBuilder.NAME, TermsAggregationBuilder::new, TermsAggregationBuilder::parse));
        }
    };
    expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, singletonList(registersDupeAggregation)).getNamedXContents()));
    SearchPlugin registersDupePipelineAggregation = new SearchPlugin() {

        public List<PipelineAggregationSpec> getPipelineAggregations() {
            return singletonList(new PipelineAggregationSpec(DerivativePipelineAggregationBuilder.NAME, DerivativePipelineAggregationBuilder::new, DerivativePipelineAggregator::new, DerivativePipelineAggregationBuilder::parse).addResultReader(InternalDerivative::new));
        }
    };
    expectThrows(IllegalArgumentException.class, () -> new NamedXContentRegistry(new SearchModule(Settings.EMPTY, false, singletonList(registersDupePipelineAggregation)).getNamedXContents()));
}
Also used : MovAvgModel(org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel) ExplainFetchSubPhase(org.elasticsearch.search.fetch.subphase.ExplainFetchSubPhase) SearchPlugin(org.elasticsearch.plugins.SearchPlugin) DerivativePipelineAggregationBuilder(org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder) PlainHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter) DerivativePipelineAggregator(org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator) ExplainFetchSubPhase(org.elasticsearch.search.fetch.subphase.ExplainFetchSubPhase) FetchSubPhase(org.elasticsearch.search.fetch.FetchSubPhase) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) CustomHighlighter(org.elasticsearch.search.fetch.subphase.highlight.CustomHighlighter) PlainHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter) FastVectorHighlighter(org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter) Highlighter(org.elasticsearch.search.fetch.subphase.highlight.Highlighter) PostingsHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PostingsHighlighter)

Example 2 with Highlighter

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

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("postings", new PostingsHighlighter());
    highlighters.register("unified", new UnifiedHighlighter());
    highlighters.extractAndRegister(plugins, SearchPlugin::getHighlighters);
    return unmodifiableMap(highlighters.getRegistry());
}
Also used : NamedRegistry(org.elasticsearch.common.NamedRegistry) SearchPlugin(org.elasticsearch.plugins.SearchPlugin) PostingsHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PostingsHighlighter) UnifiedHighlighter(org.elasticsearch.search.fetch.subphase.highlight.UnifiedHighlighter) PlainHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter) FastVectorHighlighter(org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter) FastVectorHighlighter(org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter) UnifiedHighlighter(org.elasticsearch.search.fetch.subphase.highlight.UnifiedHighlighter) PlainHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter) Highlighter(org.elasticsearch.search.fetch.subphase.highlight.Highlighter) PostingsHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PostingsHighlighter)

Example 3 with Highlighter

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

the class SearchModuleTests method testRegisterHighlighter.

public void testRegisterHighlighter() {
    CustomHighlighter customHighlighter = new CustomHighlighter();
    SearchModule module = new SearchModule(Settings.EMPTY, false, 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(PostingsHighlighter.class, highlighters.get("postings").getClass());
    assertSame(highlighters.get("custom"), customHighlighter);
}
Also used : CustomHighlighter(org.elasticsearch.search.fetch.subphase.highlight.CustomHighlighter) SearchPlugin(org.elasticsearch.plugins.SearchPlugin) CustomHighlighter(org.elasticsearch.search.fetch.subphase.highlight.CustomHighlighter) PlainHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter) FastVectorHighlighter(org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter) Highlighter(org.elasticsearch.search.fetch.subphase.highlight.Highlighter) PostingsHighlighter(org.elasticsearch.search.fetch.subphase.highlight.PostingsHighlighter)

Aggregations

SearchPlugin (org.elasticsearch.plugins.SearchPlugin)3 FastVectorHighlighter (org.elasticsearch.search.fetch.subphase.highlight.FastVectorHighlighter)3 Highlighter (org.elasticsearch.search.fetch.subphase.highlight.Highlighter)3 PlainHighlighter (org.elasticsearch.search.fetch.subphase.highlight.PlainHighlighter)3 PostingsHighlighter (org.elasticsearch.search.fetch.subphase.highlight.PostingsHighlighter)3 CustomHighlighter (org.elasticsearch.search.fetch.subphase.highlight.CustomHighlighter)2 NamedRegistry (org.elasticsearch.common.NamedRegistry)1 NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)1 DerivativePipelineAggregationBuilder (org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregationBuilder)1 DerivativePipelineAggregator (org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator)1 MovAvgModel (org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel)1 FetchSubPhase (org.elasticsearch.search.fetch.FetchSubPhase)1 ExplainFetchSubPhase (org.elasticsearch.search.fetch.subphase.ExplainFetchSubPhase)1 UnifiedHighlighter (org.elasticsearch.search.fetch.subphase.highlight.UnifiedHighlighter)1