public void onModule(ScriptModule module) {
   module.registerScript(
       NativeSignificanceScoreScriptNoParams.NATIVE_SIGNIFICANCE_SCORE_SCRIPT_NO_PARAMS,
       NativeSignificanceScoreScriptNoParams.Factory.class);
   module.registerScript(
       NativeSignificanceScoreScriptWithParams.NATIVE_SIGNIFICANCE_SCORE_SCRIPT_WITH_PARAMS,
       NativeSignificanceScoreScriptWithParams.Factory.class);
 }
 public void onModule(ScriptModule module) {
   module.registerScript(
       NativeNaiveTFIDFScoreScript.NATIVE_NAIVE_TFIDF_SCRIPT_SCORE,
       NativeNaiveTFIDFScoreScript.Factory.class);
   module.registerScript(
       NativeConstantForLoopScoreScript.NATIVE_CONSTANT_FOR_LOOP_SCRIPT_SCORE,
       NativeConstantForLoopScoreScript.Factory.class);
   module.registerScript(
       NativeConstantScoreScript.NATIVE_CONSTANT_SCRIPT_SCORE,
       NativeConstantScoreScript.Factory.class);
   module.registerScript(
       NativePayloadSumScoreScript.NATIVE_PAYLOAD_SUM_SCRIPT_SCORE,
       NativePayloadSumScoreScript.Factory.class);
   module.registerScript(
       NativePayloadSumNoRecordScoreScript.NATIVE_PAYLOAD_SUM_NO_RECORD_SCRIPT_SCORE,
       NativePayloadSumNoRecordScoreScript.Factory.class);
 }
  /** Setup for the whole base test class. */
  @BeforeClass
  public static void init() throws IOException {
    // we have to prefer CURRENT since with the range of versions we support
    // it's rather unlikely to get the current actually.
    Version version =
        randomBoolean()
            ? Version.CURRENT
            : VersionUtils.randomVersionBetween(random(), Version.V_2_0_0_beta1, Version.CURRENT);
    Settings settings =
        Settings.builder()
            .put("node.name", AbstractQueryTestCase.class.toString())
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false)
            .build();

    index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
    Settings indexSettings =
        Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
    final ThreadPool threadPool = new ThreadPool(settings);
    final ClusterService clusterService = createClusterService(threadPool);
    setState(
        clusterService,
        new ClusterState.Builder(clusterService.state())
            .metaData(
                new MetaData.Builder()
                    .put(
                        new IndexMetaData.Builder(index.getName())
                            .settings(indexSettings)
                            .numberOfShards(1)
                            .numberOfReplicas(0))));
    ScriptModule scriptModule = newTestScriptModule();
    List<Setting<?>> scriptSettings = scriptModule.getSettings();
    scriptSettings.add(InternalSettingsPlugin.VERSION_CREATED);
    SettingsModule settingsModule =
        new SettingsModule(settings, scriptSettings, Collections.emptyList());

    IndicesModule indicesModule =
        new IndicesModule(Collections.emptyList()) {
          @Override
          protected void configure() {
            bindMapperExtension();
          }
        };
    SearchModule searchModule =
        new SearchModule(settings, false, emptyList()) {
          @Override
          protected void configureSearch() {
            // Skip me
          }
        };
    List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
    entries.addAll(indicesModule.getNamedWriteables());
    entries.addAll(searchModule.getNamedWriteables());
    namedWriteableRegistry = new NamedWriteableRegistry(entries);
    injector =
        new ModulesBuilder()
            .add(
                (b) -> {
                  b.bind(Environment.class).toInstance(new Environment(settings));
                  b.bind(ThreadPool.class).toInstance(threadPool);
                  b.bind(ScriptService.class).toInstance(scriptModule.getScriptService());
                },
                settingsModule,
                indicesModule,
                searchModule,
                new IndexSettingsModule(index, settings),
                new AbstractModule() {
                  @Override
                  protected void configure() {
                    bind(ClusterService.class).toInstance(clusterService);
                    bind(CircuitBreakerService.class).toInstance(new NoneCircuitBreakerService());
                    bind(NamedWriteableRegistry.class).toInstance(namedWriteableRegistry);
                  }
                })
            .createInjector();
    aggParsers = injector.getInstance(SearchRequestParsers.class).aggParsers;
    // create some random type with some default field, those types will
    // stick around for all of the subclasses
    currentTypes = new String[randomIntBetween(0, 5)];
    for (int i = 0; i < currentTypes.length; i++) {
      String type = randomAsciiOfLengthBetween(1, 10);
      currentTypes[i] = type;
    }
    queriesRegistry = injector.getInstance(IndicesQueriesRegistry.class);
    parseFieldMatcher = ParseFieldMatcher.STRICT;
  }
Ejemplo n.º 4
0
 @Override
 public void processModule(Module module) {
   if (module instanceof ScriptModule) {
     ((ScriptModule) module).addScriptEngine(GroovyScriptEngineService.class);
   }
 }
 /** @param scriptModule The scriptModule to register this script on */
 public void onModule(ScriptModule scriptModule) {
   scriptModule.registerScript(name(), LocationScriptFactory.class);
 }
Ejemplo n.º 6
0
 public void onModule(ScriptModule module) {
   module.addScriptEngine(FieldValueScriptEngine.class);
 }
Ejemplo n.º 7
0
 public void onModule(ScriptModule module) {
   module.addScriptEngine(ExtractFieldScriptEngine.class);
 }
  @Before
  public void setup() throws IOException {
    Settings settings =
        Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
            .put(Environment.PATH_CONF_SETTING.getKey(), this.getDataPath("config"))
            .put("node.name", getClass().getName())
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();
    final Client proxy =
        (Client)
            Proxy.newProxyInstance(
                Client.class.getClassLoader(),
                new Class<?>[] {Client.class},
                (proxy1, method, args) -> {
                  throw new UnsupportedOperationException("client is just a dummy");
                });
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings);
    Index index = idxSettings.getIndex();
    SettingsModule settingsModule = new SettingsModule(settings);
    ScriptModule scriptModule = new ScriptModule();
    scriptModule.prepareSettings(settingsModule);
    // TODO: make this use a mock engine instead of mustache and it will no longer be messy!
    scriptModule.addScriptEngine(
        new ScriptEngineRegistry.ScriptEngineRegistration(
            MustacheScriptEngineService.class, MustacheScriptEngineService.TYPES));
    settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED);
    injector =
        new ModulesBuilder()
            .add(
                new EnvironmentModule(new Environment(settings)),
                settingsModule,
                new ThreadPoolModule(new ThreadPool(settings)),
                new SearchModule(settings, new NamedWriteableRegistry()) {
                  @Override
                  protected void configureSearch() {
                    // skip so we don't need transport
                  }
                },
                scriptModule,
                new IndexSettingsModule(index, settings),
                new AbstractModule() {
                  @Override
                  protected void configure() {
                    bind(Client.class).toInstance(proxy); // not needed here
                    Multibinder.newSetBinder(binder(), ScoreFunctionParser.class);
                    bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
                    bind(CircuitBreakerService.class).to(NoneCircuitBreakerService.class);
                  }
                })
            .createInjector();

    AnalysisService analysisService =
        new AnalysisRegistry(null, new Environment(settings)).build(idxSettings);
    ScriptService scriptService = injector.getInstance(ScriptService.class);
    SimilarityService similarityService =
        new SimilarityService(idxSettings, Collections.emptyMap());
    MapperRegistry mapperRegistry = new IndicesModule().getMapperRegistry();
    MapperService mapperService =
        new MapperService(
            idxSettings, analysisService, similarityService, mapperRegistry, () -> context);
    IndicesFieldDataCache cache =
        new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {});
    IndexFieldDataService indexFieldDataService =
        new IndexFieldDataService(
            idxSettings, cache, injector.getInstance(CircuitBreakerService.class), mapperService);
    BitsetFilterCache bitsetFilterCache =
        new BitsetFilterCache(
            idxSettings,
            new BitsetFilterCache.Listener() {
              @Override
              public void onCache(ShardId shardId, Accountable accountable) {}

              @Override
              public void onRemoval(ShardId shardId, Accountable accountable) {}
            });
    IndicesQueriesRegistry indicesQueriesRegistry =
        injector.getInstance(IndicesQueriesRegistry.class);
    context =
        new QueryShardContext(
            idxSettings,
            bitsetFilterCache,
            indexFieldDataService,
            mapperService,
            similarityService,
            scriptService,
            indicesQueriesRegistry,
            null,
            null);
  }
 public void onModule(ScriptModule module) {
   module.addScriptEngine(MvelScriptEngineService.class);
 }