/// <summary> /// Fields prefixed with "___" will not be stored. /// </summary> /// <returns>Document ID</returns> public void Write(IDictionary <string, object> document) { document["__created"] = DateTime.Now.ToBinary(); var docMap = new List <(long keyId, long valId)>(); var docId = _docIx.GetNextDocId(); foreach (var key in document.Keys) { var val = document[key]; if (val == null) { continue; } var keyStr = key.ToString(); if (keyStr.StartsWith("___")) { continue; } var keyHash = keyStr.ToHash(); long keyId; if (!SessionFactory.TryGetKeyId(CollectionId, keyHash, out keyId)) { // We have a new key! // store key var keyInfo = _keys.Append(keyStr); keyId = _keyIx.Append(keyInfo.offset, keyInfo.len, keyInfo.dataType); SessionFactory.PersistKeyMapping(CollectionId, keyHash, keyId); } // store value var valInfo = _vals.Append(val); var valId = _valIx.Append(valInfo.offset, valInfo.len, valInfo.dataType); // store refs to keys and values docMap.Add((keyId, valId)); // index if (!keyStr.StartsWith("_") && valInfo.dataType == DataType.STRING) { _indexSession.Put(docId, keyId, (string)val); } } var docMeta = _docs.Append(docMap); _docIx.Append(docMeta.offset, docMeta.length); }
/// <summary> /// Fields prefixed with "___" will not be stored. /// </summary> /// <returns>Document ID</returns> public void Write(IDictionary document, TermIndexSession indexSession) { var docId = Write(document); indexSession.Put(docId, document); }