Ejemplo n.º 1
0
        public void Index(string field, TextReader indexedValue)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }
            if (field.Length > 256)
            {
                throw new ArgumentException("field name cannot exceed 256 characters", "field");
            }
            if (indexedValue == null)
            {
                throw new ArgumentNullException("indexedValue");
            }

            var treeName = "@fld_" + field;

            _source = _analyzer.CreateTokenSource(field, _source);
            _source.SetReader(indexedValue);
            while (_source.Next())
            {
                if (_analyzer.Process(field, _source) == false)
                {
                    continue;
                }

                var byteCount = Encoding.UTF8.GetByteCount(_source.Buffer, 0, _source.Size);
                if (byteCount > 256)
                {
                    throw new IOException("Cannot index a term that is greater than 256 bytes, but got a term with " +
                                          byteCount + " bytes");
                }
                var bytes = _bufferPool.Take(byteCount);
                _toBeFreed.Add(bytes);
                Encoding.UTF8.GetBytes(_source.Buffer, 0, _source.Size, bytes, 0);

                _writeBatch.MultiAdd(new Slice(bytes, (ushort)byteCount), _currentDocumentIdSlice, treeName);
            }
        }