Java Code Examples for org.apache.lucene.codecs.perfield.PerFieldPostingsFormat

The following examples show how to use org.apache.lucene.codecs.perfield.PerFieldPostingsFormat. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mtas   Source File: MtasCodec.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public PostingsFormat postingsFormat() {
  initDelegate();
  if (delegate.postingsFormat() instanceof PerFieldPostingsFormat) {
    Codec defaultCodec = Codec.getDefault();
    PostingsFormat defaultPostingsFormat = defaultCodec.postingsFormat();
    if (defaultPostingsFormat instanceof PerFieldPostingsFormat) {
      defaultPostingsFormat = ((PerFieldPostingsFormat) defaultPostingsFormat)
          .getPostingsFormatForField(null);
      if ((defaultPostingsFormat == null)
          || (defaultPostingsFormat instanceof PerFieldPostingsFormat)) {
        // fallback option
        return new MtasCodecPostingsFormat(
            PostingsFormat.forName("Lucene70"));
      } else {
        return new MtasCodecPostingsFormat(defaultPostingsFormat);
      }
    } else {
      return new MtasCodecPostingsFormat(defaultPostingsFormat);
    }
  } else {
    return new MtasCodecPostingsFormat(delegate.postingsFormat());
  }
}
 
Example 2
Source Project: lucene-solr   Source File: TestUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getPostingsFormat(Codec codec, String field) {
  PostingsFormat p = codec.postingsFormat();
  if (p instanceof PerFieldPostingsFormat) {
    return ((PerFieldPostingsFormat)p).getPostingsFormatForField(field).getName();
  } else {
    return p.getName();
  }
}
 
Example 3
Source Project: lucene-solr   Source File: TestCodecSupport.java    License: Apache License 2.0 5 votes vote down vote up
public void testPostingsFormats() {
  Codec codec = h.getCore().getCodec();
  Map<String, SchemaField> fields = h.getCore().getLatestSchema().getFields();
  SchemaField schemaField = fields.get("string_direct_f");
  PerFieldPostingsFormat format = (PerFieldPostingsFormat) codec.postingsFormat();
  assertEquals("Direct", format.getPostingsFormatForField(schemaField.getName()).getName());
  schemaField = fields.get("string_standard_f");
  assertEquals(TestUtil.getDefaultPostingsFormat().getName(), format.getPostingsFormatForField(schemaField.getName()).getName());
  schemaField = fields.get("string_f");
  assertEquals(TestUtil.getDefaultPostingsFormat().getName(), format.getPostingsFormatForField(schemaField.getName()).getName());
}
 
Example 4
Source Project: lucene-solr   Source File: TestCodecSupport.java    License: Apache License 2.0 5 votes vote down vote up
public void testDynamicFieldsPostingsFormats() {
  Codec codec = h.getCore().getCodec();
  PerFieldPostingsFormat format = (PerFieldPostingsFormat) codec.postingsFormat();

  assertEquals("Direct", format.getPostingsFormatForField("foo_direct").getName());
  assertEquals("Direct", format.getPostingsFormatForField("bar_direct").getName());
  assertEquals(TestUtil.getDefaultPostingsFormat().getName(), format.getPostingsFormatForField("foo_standard").getName());
  assertEquals(TestUtil.getDefaultPostingsFormat().getName(), format.getPostingsFormatForField("bar_standard").getName());
}