org.apache.lucene.analysis.miscellaneous.Lucene47WordDelimiterFilter.position C# (CSharp) Method

position() private method

Get the position increment gap for a subword or concatenation
private position ( bool inject ) : int
inject bool true if this token wants to be injected
return int
	  private int position(bool inject)
	  {
		int posInc = accumPosInc;

		if (hasOutputToken)
		{
		  accumPosInc = 0;
		  return inject ? 0 : Math.Max(1, posInc);
		}

		hasOutputToken = true;

		if (!hasOutputFollowingOriginal)
		{
		  // the first token following the original is 0 regardless
		  hasOutputFollowingOriginal = true;
		  return 0;
		}
		// clear the accumulated position increment
		accumPosInc = 0;
		return Math.Max(1, posInc);
	  }

Usage Example

            /// <summary>
            /// Writes the concatenation to the attributes
            /// </summary>
            internal void write()
            {
                clearAttributes();
                if (outerInstance.termAttribute.length() < buffer.Length)
                {
                    outerInstance.termAttribute.resizeBuffer(buffer.Length);
                }
                char[] termbuffer = outerInstance.termAttribute.buffer();

                buffer.getChars(0, buffer.Length, termbuffer, 0);
                outerInstance.termAttribute.Length = buffer.Length;

                if (outerInstance.hasIllegalOffsets)
                {
                    outerInstance.offsetAttribute.setOffset(outerInstance.savedStartOffset, outerInstance.savedEndOffset);
                }
                else
                {
                    outerInstance.offsetAttribute.setOffset(startOffset, endOffset);
                }
                outerInstance.posIncAttribute.PositionIncrement = outerInstance.position(true);
                outerInstance.typeAttribute.Type = outerInstance.savedType;
                outerInstance.accumPosInc        = 0;
            }