Java Code Examples for org.apache.lucene.codecs.PostingsFormat#getName()

The following examples show how to use org.apache.lucene.codecs.PostingsFormat#getName() . 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 File: CompletionFieldsConsumer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
CompletionFieldsConsumer(String codecName, PostingsFormat delegatePostingsFormat, SegmentWriteState state) throws IOException {
  this.codecName = codecName;
  this.delegatePostingsFormatName = delegatePostingsFormat.getName();
  this.state = state;
  String dictFile = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, DICT_EXTENSION);
  boolean success = false;
  try {
    this.delegateFieldsConsumer = delegatePostingsFormat.fieldsConsumer(state);
    dictOut = state.directory.createOutput(dictFile, state.context);
    CodecUtil.writeIndexHeader(dictOut, codecName, COMPLETION_VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
    success = true;
  } finally {
    if (success == false) {
      IOUtils.closeWhileHandlingException(dictOut, delegateFieldsConsumer);
    }
  }
}
 
Example 2
Source File: MtasCodecPostingsFormat.java    From mtas with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates a new mtas codec postings format.
 *
 * @param delegate the delegate
 */
public MtasCodecPostingsFormat(PostingsFormat delegate) {
  super(MtasCodec.MTAS_CODEC_NAME);
  delegateCodecName = delegate.getName();
  delegatePostingsFormat = delegate;
  // preload to prevent NoClassDefFoundErrors
  try {
    Class.forName("mtas.codec.payload.MtasPayloadDecoder");
    Class.forName("mtas.codec.payload.MtasBitInputStream");
    Class.forName("mtas.analysis.token.MtasPosition");
    Class.forName("mtas.analysis.token.MtasOffset");
    Class.forName("mtas.codec.tree.MtasRBTree");
    Class.forName("mtas.codec.MtasTerms");
    Class.forName("mtas.codec.util.CodecInfo");
    Class.forName("mtas.codec.tree.MtasTreeNodeId");
  } catch (ClassNotFoundException e) {
    log.error(e);
  }
}
 
Example 3
Source File: CrankyPostingsFormat.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
CrankyPostingsFormat(PostingsFormat delegate, Random random) {
  // we impersonate the passed-in codec, so we don't need to be in SPI,
  // and so we dont change file formats
  super(delegate.getName());
  this.delegate = delegate;
  this.random = random;
}
 
Example 4
Source File: TestUtil.java    From lucene-solr with 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 5
Source File: PerFieldPostingsFormat.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private Map<PostingsFormat, FieldsGroup> buildFieldsGroupMapping(Iterable<String> indexedFieldNames) {
  // Maps a PostingsFormat instance to the suffix it should use
  Map<PostingsFormat,FieldsGroup.Builder> formatToGroupBuilders = new HashMap<>();

  // Holds last suffix of each PostingFormat name
  Map<String,Integer> suffixes = new HashMap<>();

  // Assign field -> PostingsFormat
  for(String field : indexedFieldNames) {
    FieldInfo fieldInfo = writeState.fieldInfos.fieldInfo(field);
    // TODO: This should check current format from the field attribute?
    final PostingsFormat format = getPostingsFormatForField(field);

    if (format == null) {
      throw new IllegalStateException("invalid null PostingsFormat for field=\"" + field + "\"");
    }
    String formatName = format.getName();

    FieldsGroup.Builder groupBuilder = formatToGroupBuilders.get(format);
    if (groupBuilder == null) {
      // First time we are seeing this format; create a new instance

      // bump the suffix
      Integer suffix = suffixes.get(formatName);
      if (suffix == null) {
        suffix = 0;
      } else {
        suffix = suffix + 1;
      }
      suffixes.put(formatName, suffix);

      String segmentSuffix = getFullSegmentSuffix(field,
                                                  writeState.segmentSuffix,
                                                  getSuffix(formatName, Integer.toString(suffix)));
      groupBuilder = new FieldsGroup.Builder(suffix, new SegmentWriteState(writeState, segmentSuffix));
      formatToGroupBuilders.put(format, groupBuilder);
    } else {
      // we've already seen this format, so just grab its suffix
      if (!suffixes.containsKey(formatName)) {
        throw new IllegalStateException("no suffix for format name: " + formatName + ", expected: " + groupBuilder.suffix);
      }
    }

    groupBuilder.addField(field);

    fieldInfo.putAttribute(PER_FIELD_FORMAT_KEY, formatName);
    fieldInfo.putAttribute(PER_FIELD_SUFFIX_KEY, Integer.toString(groupBuilder.suffix));
  }

  Map<PostingsFormat,FieldsGroup> formatToGroups = new HashMap<>((int) (formatToGroupBuilders.size() / 0.75f) + 1);
  formatToGroupBuilders.forEach((postingsFormat, builder) -> formatToGroups.put(postingsFormat, builder.build()));
  return formatToGroups;
}
 
Example 6
Source File: TestPerFieldPostingsFormat2.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
MergeRecordingPostingsFormatWrapper(PostingsFormat delegate) {
  super(delegate.getName());
  this.delegate = delegate;
}