/** setup for the whole base test class */
 @BeforeClass
 public static void init() {
   if (namedWriteableRegistry == null) {
     namedWriteableRegistry = new NamedWriteableRegistry();
     SearchModule.registerSmoothingModels(namedWriteableRegistry);
   }
 }
  /** 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;
  }
 public void onModule(SearchModule module) {
   module.registerQuery(
       TestDeprecatedQueryBuilder::new,
       TestDeprecatedQueryBuilder::fromXContent,
       TestDeprecatedQueryBuilder.QUERY_NAME_FIELD);
 }
 public void onModule(SearchModule significanceModule) {
   significanceModule.registerHeuristicParser(SimpleHeuristic.SimpleHeuristicParser.class);
 }
 public void onModule(SearchModule scoreModule) {
   scoreModule.registerScoreFunction(
       CustomDistanceScoreBuilder::new,
       CustomDistanceScoreBuilder.PARSER,
       CustomDistanceScoreBuilder.FUNCTION_NAME_FIELD);
 }