Example usage for org.apache.lucene.codecs Codec getDefault

List of usage examples for org.apache.lucene.codecs Codec getDefault

Introduction

In this page you can find the example usage for org.apache.lucene.codecs Codec getDefault.

Prototype

public static Codec getDefault() 

Source Link

Document

expert: returns the default codec used for newly created IndexWriterConfig s.

Usage

From source file:com.b2international.index.Activator.java

License:Apache License

public void start(BundleContext context) throws Exception {

    Bundle bundle = context.getBundle();
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    bundleClassLoader = bundleWiring.getClassLoader();

    /*/*from  w ww  .  j a v a 2  s.c o m*/
     * Trigger default Codec class loading. 
     * This way we prevent that the class loading will be performed by a thread started from the Lucene's core bundle.
     */
    Codec.getDefault();

    // Prevent Log4j2 from registering a shutdown hook; we will manage the logging system's lifecycle manually.
    System.setProperty("log4j.shutdownHookEnabled", "false");

    withTccl(() -> {
        // Initialize Log4j2
        LogManager.getContext();

        /* 
         * FIXME: Set the default response consumer factory via reflection to allow processing greater than 
         * 100 MB of data as its input. Reflection is a really bad (but also the only) way of doing this at
         * the moment!
         */
        final HttpAsyncResponseConsumerFactory consumerFactory = new HeapBufferedResponseConsumerFactory(
                LARGE_BUFFER_LIMIT);
        final Field defaultField = HttpAsyncResponseConsumerFactory.class.getDeclaredField("DEFAULT");
        defaultField.setAccessible(true);

        final Field modifiers = Field.class.getDeclaredField("modifiers");
        modifiers.setAccessible(true);
        modifiers.setInt(defaultField, defaultField.getModifiers() & ~Modifier.FINAL);

        defaultField.set(null, consumerFactory);

        // Initialize Elasticsearch's XContent extensibility mechanism 
        return JsonXContent.contentBuilder();
    });
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinitionTest.java

License:Apache License

@Test
public void codecConfig() throws Exception {
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
    assertNotNull(defn.getCodec());/*  w  w w.j av a2s .c o m*/
    assertEquals(oakCodec.getName(), defn.getCodec().getName());

    builder.setProperty(LuceneIndexConstants.FULL_TEXT_ENABLED, false);
    defn = new IndexDefinition(root, builder.getNodeState());
    assertNull(defn.getCodec());

    Codec simple = Codec.getDefault();
    builder.setProperty(LuceneIndexConstants.CODEC_NAME, simple.getName());
    defn = new IndexDefinition(root, builder.getNodeState());
    assertNotNull(defn.getCodec());
    assertEquals(simple.getName(), defn.getCodec().getName());
}

From source file:org.apache.solr.core.SolrCore.java

License:Apache License

private Codec initCodec(SolrConfig solrConfig, final IndexSchema schema) {
    final PluginInfo info = solrConfig.getPluginInfo(CodecFactory.class.getName());
    final CodecFactory factory;
    if (info != null) {
        factory = schema.getResourceLoader().newInstance(info.className, CodecFactory.class);
        factory.init(info.initArgs);/*from   w  w w. j ava  2s .  c  o m*/
    } else {
        factory = new CodecFactory() {
            @Override
            public Codec getCodec() {
                return Codec.getDefault();
            }
        };
    }
    if (factory instanceof SolrCoreAware) {
        // CodecFactory needs SolrCore before inform() is called on all registered
        // SolrCoreAware listeners, at the end of the SolrCore constructor
        ((SolrCoreAware) factory).inform(this);
    } else {
        for (FieldType ft : schema.getFieldTypes().values()) {
            if (null != ft.getPostingsFormat()) {
                String msg = "FieldType '" + ft.getTypeName()
                        + "' is configured with a postings format, but the codec does not support it: "
                        + factory.getClass();
                log.error(msg);
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
            }
            if (null != ft.getDocValuesFormat()) {
                String msg = "FieldType '" + ft.getTypeName()
                        + "' is configured with a docValues format, but the codec does not support it: "
                        + factory.getClass();
                log.error(msg);
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
            }
        }
    }
    return factory.getCodec();
}

From source file:org.apache.solr.search.function.TestFunctionQuery.java

License:Apache License

/**
 * test collection-level term stats (new in 4.x indexes)
 *//*from   w ww.  j  a  v a  2 s.c  o  m*/
public void testTotalTermFreq() throws Exception {
    assumeFalse("PreFlex codec does not support collection-level term stats",
            "Lucene3x".equals(Codec.getDefault().getName()));

    clearIndex();

    assertU(adoc("id", "1", "a_tdt", "2009-08-31T12:10:10.123Z", "b_tdt", "2009-08-31T12:10:10.124Z"));
    assertU(adoc("id", "2", "a_t", "how now brown cow"));
    assertU(commit()); // create more than one segment
    assertU(adoc("id", "3", "a_t", "brown cow"));
    assertU(adoc("id", "4"));
    assertU(commit()); // create more than one segment
    assertU(adoc("id", "5"));
    assertU(adoc("id", "6", "a_t", "cow cow cow cow cow"));
    assertU(commit());
    assertQ(req("fl", "*,score", "q", "{!func}totaltermfreq('a_t','cow')", "fq", "id:6"),
            "//float[@name='score']='7.0'");
    assertQ(req("fl", "*,score", "q", "{!func}ttf(a_t,'cow')", "fq", "id:6"), "//float[@name='score']='7.0'");
    assertQ(req("fl", "*,score", "q", "{!func}sumtotaltermfreq('a_t')", "fq", "id:6"),
            "//float[@name='score']='11.0'");
    assertQ(req("fl", "*,score", "q", "{!func}sttf(a_t)", "fq", "id:6"), "//float[@name='score']='11.0'");
}

From source file:org.elasticsearch.codecs.CodecTests.java

License:Apache License

public void testAcceptPostingsFormat() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
            .startObject("field").field("type", "string")
            .field("postings_format", Codec.getDefault().postingsFormat().getName()).endObject().endObject()
            .endObject().endObject().string();
    int i = 0;/*  ww  w  . j  a  va2  s . c o m*/
    for (Version v : VersionUtils.allVersions()) {
        IndexService indexService = createIndex("test_" + i++,
                Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, v).build());
        DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
        try {
            parser.parse("type", new CompressedXContent(mapping));
            if (v.onOrAfter(Version.V_2_0_0_beta1)) {
                fail("Elasticsearch 2.0 should not support custom postings formats");
            }
        } catch (MapperParsingException e) {
            if (v.before(Version.V_2_0_0_beta1)) {
                // Elasticsearch 1.x should ignore custom postings formats
                throw e;
            }
            Assert.assertThat(e.getMessage(), containsString("unsupported parameters:  [postings_format"));
        }
    }
}

From source file:org.elasticsearch.codecs.CodecTests.java

License:Apache License

public void testAcceptDocValuesFormat() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
            .startObject("field").field("type", "string")
            .field("doc_values_format", Codec.getDefault().docValuesFormat().getName()).endObject().endObject()
            .endObject().endObject().string();
    int i = 0;//from  ww  w  . j a  va  2s.c  o m
    for (Version v : VersionUtils.allVersions()) {
        IndexService indexService = createIndex("test_" + i++,
                Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, v).build());
        DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
        try {
            parser.parse("type", new CompressedXContent(mapping));
            if (v.onOrAfter(Version.V_2_0_0_beta1)) {
                fail("Elasticsearch 2.0 should not support custom postings formats");
            }
        } catch (MapperParsingException e) {
            if (v.before(Version.V_2_0_0_beta1)) {
                // Elasticsearch 1.x should ignore custom postings formats
                throw e;
            }
            Assert.assertThat(e.getMessage(), containsString("unsupported parameters:  [doc_values_format"));
        }
    }
}

From source file:org.elasticsearch.index.codec.CodecService.java

License:Apache License

@Inject
public CodecService(Index index, @IndexSettings Settings indexSettings,
        PostingsFormatService postingsFormatService, DocValuesFormatService docValuesFormatService,
        MapperService mapperService) {//from ww  w.  ja v a  2 s  .co  m
    super(index, indexSettings);
    this.postingsFormatService = postingsFormatService;
    this.docValuesFormatService = docValuesFormatService;
    this.mapperService = mapperService;
    MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
    if (mapperService == null) {
        codecs.put(DEFAULT_CODEC, Codec.getDefault());
    } else {
        codecs.put(DEFAULT_CODEC,
                new PerFieldMappingPostingFormatCodec(mapperService,
                        postingsFormatService.get(PostingsFormatService.DEFAULT_FORMAT).get(),
                        docValuesFormatService.get(DocValuesFormatService.DEFAULT_FORMAT).get(), logger));
    }
    for (String codec : Codec.availableCodecs()) {
        codecs.put(codec, Codec.forName(codec));
    }
    this.codecs = codecs.immutableMap();
    this.loadBloomFilter = indexSettings.getAsBoolean(INDEX_CODEC_BLOOM_LOAD, INDEX_CODEC_BLOOM_LOAD_DEFAULT);
}

From source file:org.elasticsearch.index.codec.CodecTests.java

License:Apache License

@Test
public void testResolveDefaultPostingFormats() throws Exception {
    PostingsFormatService postingsFormatService = createCodecService().postingsFormatService();
    assertThat(postingsFormatService.get("default"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("default").get(), instanceOf(Elasticsearch090PostingsFormat.class));

    // Should fail when upgrading Lucene with codec changes
    assertThat(/* w ww.  ja  v a2  s.  co m*/
            ((Elasticsearch090PostingsFormat) postingsFormatService.get("default").get()).getDefaultWrapped(),
            instanceOf(((PerFieldPostingsFormat) Codec.getDefault().postingsFormat())
                    .getPostingsFormatForField("").getClass()));
    assertThat(postingsFormatService.get("Lucene41"), instanceOf(PreBuiltPostingsFormatProvider.class));
    // Should fail when upgrading Lucene with codec changes
    assertThat(postingsFormatService.get("Lucene41").get(),
            instanceOf(((PerFieldPostingsFormat) Codec.getDefault().postingsFormat())
                    .getPostingsFormatForField(null).getClass()));

    assertThat(postingsFormatService.get("bloom_default"), instanceOf(PreBuiltPostingsFormatProvider.class));
    if (PostingFormats.luceneBloomFilter) {
        assertThat(postingsFormatService.get("bloom_default").get(),
                instanceOf(BloomFilteringPostingsFormat.class));
    } else {
        assertThat(postingsFormatService.get("bloom_default").get(),
                instanceOf(BloomFilterPostingsFormat.class));
    }
    assertThat(postingsFormatService.get("BloomFilter"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("BloomFilter").get(), instanceOf(BloomFilteringPostingsFormat.class));

    assertThat(postingsFormatService.get("XBloomFilter"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("XBloomFilter").get(), instanceOf(BloomFilterPostingsFormat.class));

    if (PostingFormats.luceneBloomFilter) {
        assertThat(postingsFormatService.get("bloom_pulsing").get(),
                instanceOf(BloomFilteringPostingsFormat.class));
    } else {
        assertThat(postingsFormatService.get("bloom_pulsing").get(),
                instanceOf(BloomFilterPostingsFormat.class));
    }

    assertThat(postingsFormatService.get("pulsing"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("pulsing").get(), instanceOf(Pulsing41PostingsFormat.class));
    assertThat(postingsFormatService.get("Pulsing41"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("Pulsing41").get(), instanceOf(Pulsing41PostingsFormat.class));

    assertThat(postingsFormatService.get("memory"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("memory").get(), instanceOf(MemoryPostingsFormat.class));
    assertThat(postingsFormatService.get("Memory"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("Memory").get(), instanceOf(MemoryPostingsFormat.class));

    assertThat(postingsFormatService.get("direct"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("direct").get(), instanceOf(DirectPostingsFormat.class));
    assertThat(postingsFormatService.get("Direct"), instanceOf(PreBuiltPostingsFormatProvider.class));
    assertThat(postingsFormatService.get("Direct").get(), instanceOf(DirectPostingsFormat.class));
}

From source file:org.elasticsearch.index.codec.docvaluesformat.DefaultDocValuesFormatProvider.java

License:Apache License

@Inject
public DefaultDocValuesFormatProvider(@Assisted String name, @Assisted Settings docValuesFormatSettings) {
    super(name);/*from   ww w. ja va 2  s  .c  o m*/
    this.docValuesFormat = Codec.getDefault().docValuesFormat();
}

From source file:org.elasticsearch.index.engine.EngineTestCase.java

License:Apache License

@Override
@Before//from   w w  w  .  j  av  a2 s . com
public void setUp() throws Exception {
    super.setUp();

    CodecService codecService = new CodecService(null, logger);
    String name = Codec.getDefault().getName();
    if (Arrays.asList(codecService.availableCodecs()).contains(name)) {
        // some codecs are read only so we only take the ones that we have in the service and randomly
        // selected by lucene test case.
        codecName = name;
    } else {
        codecName = "default";
    }
    defaultSettings = IndexSettingsModule.newIndexSettings("test",
            Settings.builder().put(IndexSettings.INDEX_GC_DELETES_SETTING.getKey(), "1h") // make sure this doesn't kick in on us
                    .put(EngineConfig.INDEX_CODEC_SETTING.getKey(), codecName)
                    .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
                    .put(IndexSettings.MAX_REFRESH_LISTENERS_PER_SHARD.getKey(),
                            between(10, 10 * IndexSettings.MAX_REFRESH_LISTENERS_PER_SHARD.get(Settings.EMPTY)))
                    .build()); // TODO randomize more settings
    threadPool = new TestThreadPool(getClass().getName());
    store = createStore();
    storeReplica = createStore();
    Lucene.cleanLuceneIndex(store.directory());
    Lucene.cleanLuceneIndex(storeReplica.directory());
    primaryTranslogDir = createTempDir("translog-primary");
    engine = createEngine(store, primaryTranslogDir);
    LiveIndexWriterConfig currentIndexWriterConfig = engine.getCurrentIndexWriterConfig();

    assertEquals(engine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        engine.config().setEnableGcDeletes(false);
    }
    replicaTranslogDir = createTempDir("translog-replica");
    replicaEngine = createEngine(storeReplica, replicaTranslogDir);
    currentIndexWriterConfig = replicaEngine.getCurrentIndexWriterConfig();

    assertEquals(replicaEngine.config().getCodec().getName(), codecService.codec(codecName).getName());
    assertEquals(currentIndexWriterConfig.getCodec().getName(), codecService.codec(codecName).getName());
    if (randomBoolean()) {
        engine.config().setEnableGcDeletes(false);
    }
}