예제 #1
0
        public void Put(Document document)
        {
            var docMap = new List <(long keyId, long valId)>();

            document.Id = _streamWriter.IncrementDocId();

            foreach (var field in document.Fields)
            {
                field.DocumentId = document.Id;

                if (field.Value != null && field.Store)
                {
                    Write(field, docMap);
                }
                else
                {
                    continue;
                }
            }

            //if (!document.TryGetValue(SystemFields.CollectionId, out _))
            //{
            //    Write(SystemFields.CollectionId, _collectionId, docMap);
            //}

            Write(SystemFields.Created, DateTime.Now.ToBinary(), docMap);

            var docMeta = _streamWriter.PutDocumentMap(docMap);

            _streamWriter.PutDocumentAddress(document.Id, docMeta.offset, docMeta.length);
        }
예제 #2
0
        public long Write(IDictionary <string, object> document, HashSet <string> storedFieldNames)
        {
            var docMap = new List <(long keyId, long valId)>();

            foreach (var key in document.Keys)
            {
                var val = document[key];

                if (val != null && storedFieldNames.Contains(key))
                {
                    Write(key, val, docMap);
                }
                else
                {
                    continue;
                }
            }

            object collectionId;

            if (!document.TryGetValue(SystemFields.CollectionId, out collectionId))
            {
                collectionId = _collectionId;
            }

            object sourceDocId;

            if (document.TryGetValue(SystemFields.DocumentId, out sourceDocId))
            {
                Write(SystemFields.DocumentId, (long)sourceDocId, docMap);
            }

            Write(SystemFields.Created, DateTime.Now.ToBinary(), docMap);
            Write(SystemFields.CollectionId, collectionId, docMap);

            var docMeta = _streamWriter.PutDocumentMap(docMap);
            var docId   = _streamWriter.IncrementDocId();

            _streamWriter.PutDocumentAddress(docId, docMeta.offset, docMeta.length);

            return(docId);
        }