/* ========================================================================== Operations */ public void AddDocument(IndexDocument document) { var versionId = document.GetIntegerValue(IndexFieldName.VersionId); var storedFields = document.Where(f => f.Store == IndexStoringMode.Yes).ToList(); if (storedFields.Count > 0) { StoredData.Add(new Tuple <int, List <IndexField> >(versionId, storedFields)); } foreach (var field in document) { var fieldName = field.Name; if (!IndexData.TryGetValue(fieldName, out var existingFieldData)) { existingFieldData = new Dictionary <string, List <int> >(); IndexData.Add(fieldName, existingFieldData); } var fieldValues = GetValues(field); foreach (var fieldValue in fieldValues) { if (!existingFieldData.TryGetValue(fieldValue, out var versionIds)) { versionIds = new List <int>(); existingFieldData.Add(fieldValue, versionIds); } versionIds.Add(versionId); } } }
private void WriteTo(string rootPath, IndexDocument document) { if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(rootPath); } var nodeId = document.GetIntegerValue(IndexFieldName.NodeId); var versionId = document.GetIntegerValue(IndexFieldName.VersionId); var contentType = document.GetStringValue(IndexFieldName.Type); var contentFileBase = $"{rootPath}\\{nodeId}-{versionId}-{contentType}"; var contentFile = contentFileBase; var suffix = 0; while (File.Exists(contentFile + ".txt")) { contentFile = contentFileBase + "-" + ++suffix; } contentFile = contentFile + ".txt"; using (var writer = new StreamWriter(contentFile)) { writer.WriteLine("{"); foreach (var field in document) { string value; var type = ""; switch (field.Type) { case IndexValueType.String: value = field.StringValue == null ? "null" : $"\"{field.StringValue}\""; break; case IndexValueType.StringArray: value = "[" + string.Join(", ", field.StringArrayValue.Select(s => $"\"{s}\"").ToArray()) + "]"; break; case IndexValueType.DateTime: value = $"\"{field.ValueAsString}\""; break; case IndexValueType.Long: case IndexValueType.Float: case IndexValueType.Double: value = field.ValueAsString; type = " // " + field.Type.ToString().ToLowerInvariant(); break; case IndexValueType.Bool: case IndexValueType.Int: default: value = field.ValueAsString; break; } writer.WriteLine(" {0}: {1},{2}", field.Name, value, type); } writer.WriteLine("}"); } }