Search in sources :

Example 1 with SearchPlugin

use of org.opensearch.plugins.SearchPlugin in project OpenSearch by opensearch-project.

the class SearchModule method registerScoreFunctions.

private void registerScoreFunctions(List<SearchPlugin> plugins) {
    // ScriptScoreFunctionBuilder has it own named writable because of a new script_score query
    namedWriteables.add(new NamedWriteableRegistry.Entry(ScriptScoreFunctionBuilder.class, ScriptScoreFunctionBuilder.NAME, ScriptScoreFunctionBuilder::new));
    registerScoreFunction(new ScoreFunctionSpec<>(ScriptScoreFunctionBuilder.NAME, ScriptScoreFunctionBuilder::new, ScriptScoreFunctionBuilder::fromXContent));
    registerScoreFunction(new ScoreFunctionSpec<>(GaussDecayFunctionBuilder.NAME, GaussDecayFunctionBuilder::new, GaussDecayFunctionBuilder.PARSER));
    registerScoreFunction(new ScoreFunctionSpec<>(LinearDecayFunctionBuilder.NAME, LinearDecayFunctionBuilder::new, LinearDecayFunctionBuilder.PARSER));
    registerScoreFunction(new ScoreFunctionSpec<>(ExponentialDecayFunctionBuilder.NAME, ExponentialDecayFunctionBuilder::new, ExponentialDecayFunctionBuilder.PARSER));
    registerScoreFunction(new ScoreFunctionSpec<>(RandomScoreFunctionBuilder.NAME, RandomScoreFunctionBuilder::new, RandomScoreFunctionBuilder::fromXContent));
    registerScoreFunction(new ScoreFunctionSpec<>(FieldValueFactorFunctionBuilder.NAME, FieldValueFactorFunctionBuilder::new, FieldValueFactorFunctionBuilder::fromXContent));
    // weight doesn't have its own parser, so every function supports it out of the box.
    // Can be a single function too when not associated to any other function, which is why it needs to be registered manually here.
    namedWriteables.add(new NamedWriteableRegistry.Entry(ScoreFunctionBuilder.class, WeightBuilder.NAME, WeightBuilder::new));
    registerFromPlugin(plugins, SearchPlugin::getScoreFunctions, this::registerScoreFunction);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) SearchPlugin(org.opensearch.plugins.SearchPlugin) ScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScoreFunctionBuilder) RandomScoreFunctionBuilder(org.opensearch.index.query.functionscore.RandomScoreFunctionBuilder) ScriptScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScriptScoreFunctionBuilder) Entry(org.opensearch.common.io.stream.NamedWriteableRegistry.Entry) ScriptScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScriptScoreFunctionBuilder)

Example 2 with SearchPlugin

use of org.opensearch.plugins.SearchPlugin 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);
}
Also used : CustomHighlighter(org.opensearch.search.fetch.subphase.highlight.CustomHighlighter) SearchPlugin(org.opensearch.plugins.SearchPlugin) UnifiedHighlighter(org.opensearch.search.fetch.subphase.highlight.UnifiedHighlighter) Highlighter(org.opensearch.search.fetch.subphase.highlight.Highlighter) FastVectorHighlighter(org.opensearch.search.fetch.subphase.highlight.FastVectorHighlighter) PlainHighlighter(org.opensearch.search.fetch.subphase.highlight.PlainHighlighter) CustomHighlighter(org.opensearch.search.fetch.subphase.highlight.CustomHighlighter)

Example 3 with SearchPlugin

use of org.opensearch.plugins.SearchPlugin 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));
}
Also used : MovAvgModel(org.opensearch.search.aggregations.pipeline.MovAvgModel) ExplainPhase(org.opensearch.search.fetch.subphase.ExplainPhase) SearchPlugin(org.opensearch.plugins.SearchPlugin) DerivativePipelineAggregationBuilder(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder) PlainHighlighter(org.opensearch.search.fetch.subphase.highlight.PlainHighlighter) DerivativePipelineAggregator(org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregator) FetchSubPhase(org.opensearch.search.fetch.FetchSubPhase) UnifiedHighlighter(org.opensearch.search.fetch.subphase.highlight.UnifiedHighlighter) Highlighter(org.opensearch.search.fetch.subphase.highlight.Highlighter) FastVectorHighlighter(org.opensearch.search.fetch.subphase.highlight.FastVectorHighlighter) PlainHighlighter(org.opensearch.search.fetch.subphase.highlight.PlainHighlighter) CustomHighlighter(org.opensearch.search.fetch.subphase.highlight.CustomHighlighter)

Example 4 with SearchPlugin

use of org.opensearch.plugins.SearchPlugin in project OpenSearch by opensearch-project.

the class AggregatorTestCase method initValuesSourceRegistry.

// Make this @Before instead of @BeforeClass so it can call the non-static getSearchPlugins method
@Before
public void initValuesSourceRegistry() {
    List<SearchPlugin> plugins = new ArrayList<>(getSearchPlugins());
    plugins.add(new AggCardinalityPlugin());
    SearchModule searchModule = new SearchModule(Settings.EMPTY, plugins);
    valuesSourceRegistry = searchModule.getValuesSourceRegistry();
}
Also used : SearchPlugin(org.opensearch.plugins.SearchPlugin) ArrayList(java.util.ArrayList) SearchModule(org.opensearch.search.SearchModule) Before(org.junit.Before)

Example 5 with SearchPlugin

use of org.opensearch.plugins.SearchPlugin in project OpenSearch by opensearch-project.

the class InternalAggregationTestCase method getNamedWriteables.

/**
 * Implementors can override this if they want to provide a custom list of namedWriteables.  If the implementor
 * _just_ wants to register in namedWriteables provided by a plugin, prefer overriding
 * {@link InternalAggregationTestCase#registerPlugin()} instead because that route handles the automatic
 * conversion of AggSpecs into namedWriteables.
 */
protected List<NamedWriteableRegistry.Entry> getNamedWriteables() {
    SearchPlugin plugin = registerPlugin();
    SearchModule searchModule = new SearchModule(Settings.EMPTY, plugin == null ? emptyList() : Collections.singletonList(plugin));
    List<NamedWriteableRegistry.Entry> entries = new ArrayList<>(searchModule.getNamedWriteables());
    // Modules/plugins may have extra namedwriteables that are not added by agg specs
    if (plugin != null) {
        entries.addAll(((Plugin) plugin).getNamedWriteables());
    }
    return entries;
}
Also used : SearchPlugin(org.opensearch.plugins.SearchPlugin) ArrayList(java.util.ArrayList) SearchModule(org.opensearch.search.SearchModule)

Aggregations

SearchPlugin (org.opensearch.plugins.SearchPlugin)9 DerivativePipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder)3 ArrayList (java.util.ArrayList)2 PipelineAggregationSpec (org.opensearch.plugins.SearchPlugin.PipelineAggregationSpec)2 SearchModule (org.opensearch.search.SearchModule)2 AvgBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.AvgBucketPipelineAggregationBuilder)2 ExtendedStatsBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder)2 MaxBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.MaxBucketPipelineAggregationBuilder)2 PercentilesBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregationBuilder)2 StatsBucketPipelineAggregationBuilder (org.opensearch.search.aggregations.pipeline.StatsBucketPipelineAggregationBuilder)2 CustomHighlighter (org.opensearch.search.fetch.subphase.highlight.CustomHighlighter)2 FastVectorHighlighter (org.opensearch.search.fetch.subphase.highlight.FastVectorHighlighter)2 Highlighter (org.opensearch.search.fetch.subphase.highlight.Highlighter)2 PlainHighlighter (org.opensearch.search.fetch.subphase.highlight.PlainHighlighter)2 UnifiedHighlighter (org.opensearch.search.fetch.subphase.highlight.UnifiedHighlighter)2 Before (org.junit.Before)1 NamedRegistry (org.opensearch.common.NamedRegistry)1 ParseField (org.opensearch.common.ParseField)1 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)1 Entry (org.opensearch.common.io.stream.NamedWriteableRegistry.Entry)1