初始化

This commit is contained in:
2025-11-26 11:18:26 +08:00
commit 0564b8c1f3
579 changed files with 346253 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
//
// CreateIndexRequest.cs
//
// Author:
// MiNG <developer@ming.gz.cn>
//
// Copyright (c) 2018 Alibaba Cloud
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using Aliyun.Api.LogService.Domain.Project;
using Newtonsoft.Json;
namespace Aliyun.Api.LogService.Domain.LogStore.Index
{
public class CreateIndexRequest : ProjectScopedRequest
{
/// <summary>
/// Logstore 的名称,在 Project 下必须唯一。
/// </summary>
[JsonIgnore]
public String LogstoreName { get; }
/// <summary>
/// 全文索引对于日志中value的索引属性全文索引和字段查询必须至少配置一类。
/// </summary>
public IndexLineInfo Line { get; }
/// <summary>
/// 字段查询对于具体字段的value索引属性全文索引和字段查询必须至少配置一类。
/// </summary>
public IDictionary<String, IndexKeyInfo> Keys { get; }
public CreateIndexRequest(String logstoreName, IndexLineInfo line) : this(logstoreName, line, null)
{
// Delegate constructor.
}
public CreateIndexRequest(String logstoreName, IDictionary<String, IndexKeyInfo> keys) : this(logstoreName, null, keys)
{
// Delegate constructor.
}
public CreateIndexRequest(String logstoreName, IndexLineInfo line, IDictionary<String, IndexKeyInfo> keys)
{
this.Line = line;
this.Keys = keys;
this.LogstoreName = logstoreName;
}
}
}

View File

@@ -0,0 +1,139 @@
//
// IndexKeyInfo.cs
//
// Author:
// MiNG <developer@ming.gz.cn>
//
// Copyright (c) 2018 Alibaba Cloud
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using Aliyun.Api.LogService.Utils;
using Newtonsoft.Json;
namespace Aliyun.Api.LogService.Domain.LogStore.Index
{
/*****************************************
* TODO: Remove the coupling of Json.NET *
*****************************************/
public class IndexKeyInfo
{
/// <summary>
/// 字段类型目前支持textlongdouble和json等四种。
/// </summary>
public String Type { get; }
/// <summary>
/// 是否支持统计分析默认值为false标识不支持。
/// </summary>
[JsonProperty("doc_value")]
public Boolean? DocValue { get; set; }
/// <summary>
/// 查询别名,默认为空。
/// </summary>
public String Alias { get; set; }
public IndexKeyInfo(String type)
{
this.Type = type;
}
}
public class IndexTextKeyInfo : IndexKeyInfo
{
/// <summary>
/// 是否区分大小写默认值为false表示不区分。
/// </summary>
public Boolean? CaseSensitive { get; set; }
/// <summary>
/// 分词字符列表,只支持单个英文字符。
/// </summary>
public IEnumerable<Char> Token { get; }
/// <summary>
/// 是否进行中文分词默认值为false表示不进行中文分词。
/// </summary>
public Boolean? Chn { get; set; }
public IndexTextKeyInfo(IEnumerable<Char> token)
: base("text")
{
this.Token = token.Freeze();
}
}
public class IndexLongKeyInfo : IndexKeyInfo
{
public IndexLongKeyInfo() : base("long")
{
// Empty constructor.
}
}
public class IndexDoubleKeyInfo : IndexKeyInfo
{
public IndexDoubleKeyInfo() : base("double")
{
// Empty constructor.
}
}
public class IndexJsonKeyInfo : IndexKeyInfo
{
/// <summary>
/// 分词字符列表,只支持单个英文字符。
/// </summary>
public IEnumerable<Char> Token { get; }
/// <summary>
/// 是否进行中文分词默认值为false表示不进行中文分词。
/// </summary>
public Boolean? Chn { get; set; }
/// <summary>
/// 是否对所有json key进行索引默认为否。
/// </summary>
[JsonProperty("index_all")]
public Boolean? IndexAll { get; set; }
/// <summary>
/// 表示解析json的最大深度。
/// </summary>
[JsonProperty("max_depth")]
public Int32 MaxDepth { get; }
/// <summary>
/// 表示json中具体key的索引属性。 其中object中每个item支持textlong和double三种类型属性对应类型一致。
/// </summary>
[JsonProperty("json_keys")]
public IDictionary<String, IndexKeyInfo> JsonKeys { get; set; }
public IndexJsonKeyInfo(IEnumerable<Char> token, Int32 maxDepth)
: base("json")
{
this.Token = token.Freeze();
this.MaxDepth = maxDepth;
}
}
}

View File

@@ -0,0 +1,141 @@
//
// IndexKeysBuilder.cs
//
// Author:
// MiNG <developer@ming.gz.cn>
//
// Copyright (c) 2018 Alibaba Cloud
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using Aliyun.Api.LogService.Utils;
namespace Aliyun.Api.LogService.Domain.LogStore.Index
{
public class IndexKeysBuilder
{
private readonly Boolean allowJson;
private readonly IDictionary<String, IndexKeyInfo> keys = new Dictionary<String, IndexKeyInfo>();
public IndexKeysBuilder() : this(true)
{
// Empty constructor.
}
private IndexKeysBuilder(Boolean allowJson)
{
this.allowJson = allowJson;
}
public IndexKeysBuilder AddText(String key, params Char[] token)
{
return this.AddText(key, token.AsEnumerable());
}
public IndexKeysBuilder AddText(String key, IEnumerable<Char> token, Boolean? caseSensitive = null, Boolean? chn = null)
{
var frozenToken = token?.ToArray(); // Avoid recalculate the non-reentranceable IEnumerable.
Ensure.NotEmpty(frozenToken, nameof(token));
var textKeyInfo = new IndexTextKeyInfo(frozenToken)
{
CaseSensitive = caseSensitive,
Chn = chn
};
this.keys.Add(key, textKeyInfo);
return this;
}
public IndexKeysBuilder AddLong(String key, Boolean? docValue = null, String alias = null)
{
var longKeyInfo = new IndexLongKeyInfo
{
DocValue = docValue,
Alias = alias
};
this.keys.Add(key, longKeyInfo);
return this;
}
public IndexKeysBuilder AddDouble(String key, Boolean? docValue = null, String alias = null)
{
var doubleKeyInfo = new IndexDoubleKeyInfo
{
DocValue = docValue,
Alias = alias
};
this.keys.Add(key, doubleKeyInfo);
return this;
}
public IndexKeysBuilder AddJson(String key, Int32 maxDepth, params Char[] token)
{
return this.AddJson(key, token, maxDepth);
}
public IndexKeysBuilder AddJson(String key, IEnumerable<Char> token, Int32 maxDepth,
Boolean? chn = null, Boolean? indexAll = null, Action<IndexKeysBuilder> jsonKeys = null)
{
if (!this.allowJson)
{
throw new InvalidOperationException("json index info is not support in current state.");
}
var frozenToken = token?.ToArray(); // Avoid recalculate the non-reentranceable IEnumerable.
Ensure.NotEmpty(frozenToken, nameof(token));
IDictionary<String, IndexKeyInfo> subKeys;
if (jsonKeys != null)
{
var subBuilder = new IndexKeysBuilder(false);
jsonKeys(subBuilder);
subKeys = subBuilder.Build();
} else
{
subKeys = null;
}
var jsonKeyInfo = new IndexJsonKeyInfo(frozenToken, maxDepth)
{
Chn = chn,
IndexAll = indexAll,
JsonKeys = subKeys
};
this.keys.Add(key, jsonKeyInfo);
return this;
}
public IDictionary<String, IndexKeyInfo> Build()
{
return new Dictionary<String, IndexKeyInfo>(this.keys);
}
}
}

View File

@@ -0,0 +1,55 @@
//
// IndexLineInfo.cs
//
// Author:
// MiNG <developer@ming.gz.cn>
//
// Copyright (c) 2018 Alibaba Cloud
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using Aliyun.Api.LogService.Utils;
namespace Aliyun.Api.LogService.Domain.LogStore.Index
{
public class IndexLineInfo
{
/// <summary>
/// 是否区分大小写默认值为false表示不区分。
/// </summary>
public Boolean? CaseSensitive { get; set; }
/// <summary>
/// 分词字符列表,只支持单个英文字符。
/// </summary>
public IEnumerable<Char> Token { get; }
/// <summary>
/// 是否进行中文分词默认值为false表示不进行中文分词。
/// </summary>
public Boolean? Chn { get; set; }
public IndexLineInfo(IEnumerable<Char> token)
{
this.Token = token.Freeze();
}
}
}