pull/1/head
Ogoun 3 years ago
parent 9c854201f8
commit f1f817e831

@ -26,27 +26,27 @@
{ {
return new Condition return new Condition
{ {
Json = $"{{ \"key\": \"{name}\", \"match\": {{ \"integer\": \"{value}\" }} }}" Json = $"{{ \"key\": \"{name.ToLowerInvariant()}\", \"match\": {{ \"integer\": {value} }} }}"
}; };
} }
public static Condition IntegerRange(string name, long left, long rigth, bool include_left, bool include_right) public static Condition IntegerRange(string name, long left, long rigth, bool include_left, bool include_right)
{ {
var left_cond = include_left ? $"\"lt\": null,\"lte\": {left}" : $"\"lt\": {left},\"lte\": null"; var left_cond = include_left ? $"\"lt\": null,\"lte\": {rigth}" : $"\"lt\": {rigth},\"lte\": null";
var right_cond = include_right ? $"\"gt\": null,\"gte\": {rigth}" : $"\"gt\": {rigth},\"gte\": null"; var right_cond = include_right ? $"\"gt\": null,\"gte\": {left}" : $"\"gt\": {left},\"gte\": null";
return new Condition return new Condition
{ {
Json = $"{{ \"key\": \"{name}\", \"range\": {{ {right_cond}, {left_cond} }} }}" Json = $"{{ \"key\": \"{name.ToLowerInvariant()}\", \"range\": {{ {right_cond}, {left_cond} }} }}"
}; };
} }
public static Condition FloatRange(string name, double left, double rigth, bool include_left, bool include_right) public static Condition FloatRange(string name, double left, double rigth, bool include_left, bool include_right)
{ {
var left_cond = include_left ? $"\"lt\": null,\"lte\": {left.ConvertToString()}" : $"\"lt\": {left.ConvertToString()},\"lte\": null"; var left_cond = include_left ? $"\"lt\": null,\"lte\": {rigth.ConvertToString()}" : $"\"lt\": {rigth.ConvertToString()},\"lte\": null";
var right_cond = include_right ? $"\"gt\": null,\"gte\": {rigth.ConvertToString()}" : $"\"gt\": {rigth.ConvertToString()},\"gte\": null"; var right_cond = include_right ? $"\"gt\": null,\"gte\": {left.ConvertToString()}" : $"\"gt\": {left.ConvertToString()},\"gte\": null";
return new Condition return new Condition
{ {
Json = $"{{ \"key\": \"{name}\", \"range\": {{ {left_cond}, {right_cond} }} }}" Json = $"{{ \"key\": \"{name.ToLowerInvariant()}\", \"range\": {{ {left_cond}, {right_cond} }} }}"
}; };
} }
@ -54,7 +54,7 @@
{ {
return new Condition return new Condition
{ {
Json = $"{{ \"key\": \"{name}\", \"match\": {{ \"keyword\": \"{value}\" }} }}" Json = $"{{ \"key\": \"{name.ToLowerInvariant()}\", \"match\": {{ \"keyword\": \"{value}\" }} }}"
}; };
} }
@ -62,7 +62,7 @@
{ {
return new Condition return new Condition
{ {
Json = $"{{ \"key\": \"{name}\", \"geo_bounding_box\": {{ \"bottom_right\": {{ \"lat\": {bottom_right.lat.ConvertToString()}, \"lon\": {bottom_right.lon.ConvertToString()} }}, \"top_left\": {{ \"lat\": {top_left.lat.ConvertToString()}, \"lon\": {top_left.lon.ConvertToString()} }} }} }}" Json = $"{{ \"key\": \"{name.ToLowerInvariant()}\", \"geo_bounding_box\": {{ \"bottom_right\": {{ \"lat\": {bottom_right.lat.ConvertToString()}, \"lon\": {bottom_right.lon.ConvertToString()} }}, \"top_left\": {{ \"lat\": {top_left.lat.ConvertToString()}, \"lon\": {top_left.lon.ConvertToString()} }} }} }}"
}; };
} }
@ -70,7 +70,7 @@
{ {
return new Condition return new Condition
{ {
Json = $"{{\"key\": \"{name}\", \"geo_radius\": {{\"center\": {{ \"lat\": {location.lat.ConvertToString()}, \"lon\": {location.lon.ConvertToString()} }}, \"radius\": {radius.ConvertToString()} }} }}" Json = $"{{\"key\": \"{name.ToLowerInvariant()}\", \"geo_radius\": {{\"center\": {{ \"lat\": {location.lat.ConvertToString()}, \"lon\": {location.lon.ConvertToString()} }}, \"radius\": {radius.ConvertToString()} }} }}"
}; };
} }
public override string ToJSON() public override string ToJSON()

@ -33,7 +33,7 @@ namespace ZeroLevel.Qdrant.Models.Filters
{ {
case GroupOperator.MustNot: op = "must_not"; break; case GroupOperator.MustNot: op = "must_not"; break;
case GroupOperator.Must: op = "must"; break; case GroupOperator.Must: op = "must"; break;
default: op = "mushould"; break; default: op = "should"; break;
} }
return $"\"{op}\": [{string.Join(",", _items.Select(i => i.ToJSON()))}]"; return $"\"{op}\": [{string.Join(",", _items.Select(i => i.ToJSON()))}]";
} }

@ -1,4 +1,5 @@
using System.Linq; using System;
using System.Linq;
using System.Text; using System.Text;
using ZeroLevel.Qdrant.Services; using ZeroLevel.Qdrant.Services;
using ZeroLevel.Services.Collections; using ZeroLevel.Services.Collections;
@ -35,11 +36,20 @@ namespace ZeroLevel.Qdrant.Models.Requests
} }
var converter = _cachee.Get<QdrantJsonConverter<T>>("converter"); var converter = _cachee.Get<QdrantJsonConverter<T>>("converter");
Func<UpsertPoint<T>, string> p_conv = up =>
{
if (up.id != null)
{
return $"\"id\": {up.id}, \"payload\": {{ {converter.ToJson(up.payload)} }}, \"vector\": [{ string.Join(",", up.vector.Select(f => f.ConvertToString()))}]";
}
return $"\"payload\": {{ {converter.ToJson(up.payload)} }}, \"vector\": [{ string.Join(",", up.vector.Select(f => f.ConvertToString()))}]";
};
var json = new StringBuilder(); var json = new StringBuilder();
json.Append("{"); json.Append("{");
json.Append("\"upsert_points\": {"); json.Append("\"upsert_points\": {");
json.Append("\"points\":[ {"); json.Append("\"points\":[ {");
json.Append(string.Join("},{", upsert_points.points.Select(p => $"\"id\": {p.id}, \"payload\": {{ {converter.ToJson(p.payload)} }}, \"vector\": [{ string.Join(",", p.vector.Select(f => f.ConvertToString()))}]"))); json.Append(string.Join("},{", upsert_points.points.Select(p => p_conv(p))));
json.Append("}]"); json.Append("}]");
json.Append("}"); json.Append("}");
json.Append("}"); json.Append("}");
@ -76,7 +86,10 @@ namespace ZeroLevel.Qdrant.Models.Requests
json.Append("{"); json.Append("{");
json.Append("\"upsert_points\": {"); json.Append("\"upsert_points\": {");
json.Append("\"batch\": {"); json.Append("\"batch\": {");
json.Append($"\"ids\": [{string.Join(",", upsert_points.batch.ids)}], "); if (upsert_points.batch.ids != null && upsert_points.batch.ids.Length > 0)
{
json.Append($"\"ids\": [{string.Join(",", upsert_points.batch.ids)}], ");
}
json.Append($"\"payloads\": [ {{ {string.Join("} ,{ ", upsert_points.batch.payloads.Select(payload => converter.ToJson(payload)))} }} ], "); json.Append($"\"payloads\": [ {{ {string.Join("} ,{ ", upsert_points.batch.payloads.Select(payload => converter.ToJson(payload)))} }} ], ");
json.Append($"\"vectors\": [{string.Join(",", Enumerable.Range(0, upsert_points.batch.vectors.GetLength(0)).Select(row => "[" + string.Join(",", ArrayExtensions.GetRow(upsert_points.batch.vectors, row).Select(f => f.ConvertToString())) + "]"))}]"); json.Append($"\"vectors\": [{string.Join(",", Enumerable.Range(0, upsert_points.batch.vectors.GetLength(0)).Select(row => "[" + string.Join(",", ArrayExtensions.GetRow(upsert_points.batch.vectors, row).Select(f => f.ConvertToString())) + "]"))}]");
json.Append("}"); json.Append("}");

@ -100,25 +100,25 @@ namespace ZeroLevel.Qdrant.Services
if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false) if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false)
{ {
var arr = val as IEnumerable; var arr = val as IEnumerable;
json.Append($"\"{member.Name}\": {{ \"type\": \"keyword\", \"value\": [ {string.Join(", ", E(arr).Select(v => KeywordToString(member, v)))}] }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"keyword\", \"value\": [ {string.Join(", ", E(arr).Select(v => KeywordToString(member, v)))}] }},");
} }
else else
{ {
json.Append($"\"{member.Name}\": {{ \"type\": \"keyword\", \"value\":{KeywordToString(member, val)} }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"keyword\", \"value\":{KeywordToString(member, val)} }},");
} }
break; break;
case GEO_TYPE: case GEO_TYPE:
if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false) if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false)
{ {
var arr = val as IEnumerable; var arr = val as IEnumerable;
json.Append($"\"{member.Name}\": {{ \"type\": \"geo\", \"value\": [ {string.Join(",", E(arr).Select(v => v as Location).Where(l => l != null).Select(l => $" {{ \"lon\":{l.lon.ConvertToString()}, \"lat\":{l.lat.ConvertToString()} }}"))}] }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"geo\", \"value\": [ {string.Join(",", E(arr).Select(v => v as Location).Where(l => l != null).Select(l => $" {{ \"lon\":{l.lon.ConvertToString()}, \"lat\":{l.lat.ConvertToString()} }}"))}] }},");
} }
else else
{ {
Location l = val as Location; Location l = val as Location;
if (l != null) if (l != null)
{ {
json.Append($"\"{member.Name}\": {{ \"type\": \"geo\", \"value\": {{ \"lon\":{l.lon.ConvertToString()}, \"lat\":{l.lat.ConvertToString()} }} }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"geo\", \"value\": {{ \"lon\":{l.lon.ConvertToString()}, \"lat\":{l.lat.ConvertToString()} }} }},");
} }
} }
break; break;
@ -126,23 +126,23 @@ namespace ZeroLevel.Qdrant.Services
if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false) if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false)
{ {
var arr = val as IEnumerable; var arr = val as IEnumerable;
json.Append($"\"{member.Name}\": {{ \"type\": \"float\", \"value\": [ {string.Join(",", E(arr).Select(v => Convert.ToDouble(v).ConvertToString()))}] }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"float\", \"value\": [ {string.Join(",", E(arr).Select(v => Convert.ToDouble(v).ConvertToString()))}] }},");
} }
else else
{ {
json.Append($"\"{member.Name}\": {{ \"type\": \"float\", \"value\": {Convert.ToDouble(val).ConvertToString()} }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"float\", \"value\": {Convert.ToDouble(val).ConvertToString()} }},");
} }
break; break;
case INTEGER_TYPE: case INTEGER_TYPE:
if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false) if (TypeHelpers.IsEnumerable(member.ClrType) && TypeHelpers.IsString(member.ClrType) == false)
{ {
var arr = val as IEnumerable; var arr = val as IEnumerable;
json.Append($"\"{member.Name}\": {{ \"type\": \"integer\", \"value\": [ {string.Join(",", E(arr).Select(v => Convert.ToInt64(v)))}] }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"integer\", \"value\": [ {string.Join(",", E(arr).Select(v => Convert.ToInt64(v)))}] }},");
} }
else else
{ {
json.Append($"\"{member.Name}\": {{ \"type\": \"integer\", \"value\": {Convert.ToInt64(val)} }},"); json.Append($"\"{member.Name.ToLowerInvariant()}\": {{ \"type\": \"integer\", \"value\": {Convert.ToInt64(val)} }},");
} }
break; break;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.