コード例 #1
0
        public override BytesRef encode(char[] buffer, int offset, int length)
        {
            int payload = ArrayUtil.parseInt(buffer, offset, length);     //TODO: improve this so that we don't have to new Strings

            sbyte[]  bytes  = PayloadHelper.encodeInt(payload);
            BytesRef result = new BytesRef(bytes);

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// refills buffers with new data from the current token.
        /// </summary>
        private void refill()
        {
            // compact buffers to keep them smallish if they become large
            // just a safety check, but technically we only need the last codepoint
            if (bufferLen > 64)
            {
                int last = bufferLen - 1;
                buffer[0]      = buffer[last];
                startOffset[0] = startOffset[last];
                endOffset[0]   = endOffset[last];
                bufferLen      = 1;
                index         -= last;
            }

            char[] termBuffer = termAtt.buffer();
            int    len        = termAtt.length();
            int    start      = offsetAtt.startOffset();
            int    end        = offsetAtt.endOffset();

            int newSize = bufferLen + len;

            buffer        = ArrayUtil.grow(buffer, newSize);
            startOffset   = ArrayUtil.grow(startOffset, newSize);
            endOffset     = ArrayUtil.grow(endOffset, newSize);
            lastEndOffset = end;

            if (end - start != len)
            {
                // crazy offsets (modified by synonym or charfilter): just preserve
                for (int i = 0, cp = 0; i < len; i += char.charCount(cp))
                {
                    cp = buffer[bufferLen] = char.codePointAt(termBuffer, i, len);
                    startOffset[bufferLen] = start;
                    endOffset[bufferLen]   = end;
                    bufferLen++;
                }
            }
            else
            {
                // normal offsets
                for (int i = 0, cp = 0, cpLen = 0; i < len; i += cpLen)
                {
                    cp    = buffer[bufferLen] = char.codePointAt(termBuffer, i, len);
                    cpLen = char.charCount(cp);
                    startOffset[bufferLen] = start;
                    start = endOffset[bufferLen] = start + cpLen;
                    bufferLen++;
                }
            }
        }