Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ string ParseMemberAccessDateTime()
case "System.String": callParseResult = ParseCallString(); break;
case "System.Math": callParseResult = ParseCallMath(); break;
case "System.DateTime": callParseResult = ParseCallDateTime(); break;
case "FreeRedis.RediSearch.SearchBuilderStringExtensions":
callParseResult = ParseCallStringExtension();
break;
default: callParseResult = ParseCallOther(); break;
}
if (!string.IsNullOrEmpty(callParseResult)) return callParseResult;
Expand Down Expand Up @@ -520,6 +523,41 @@ string ParseCallString()
}
return null;
}

string ParseCallStringExtension()
{
var left = parseExp(callExp.Arguments[0]);
switch (callExp.Method.Name)
{
case "GeoRadius":
var lon = parseExp(callExp.Arguments[1]);
var lat = parseExp(callExp.Arguments[2]);
var radius = parseExp(callExp.Arguments[3]);
var unit = parseExp(callExp.Arguments[4]);
return $"{left}:[{lon} {lat} {radius} {unit.Replace("'", "")}]";
case "ShapeWithin":
{
var parameterName = parseExp(callExp.Arguments[1]);
return $"{left}:[WITHIN ${parameterName.Replace("'", "")}]";
}
case "ShapeContains":
{
var parameterName = parseExp(callExp.Arguments[1]);
return $"{left}:[CONTAINS ${parameterName.Replace("'", "")}]";
}
case "ShapeIntersects":
{
var parameterName = parseExp(callExp.Arguments[1]);
return $"{left}:[INTERSECTS ${parameterName.Replace("'", "")}]";
}
case "ShapeDisjoint":
{
var parameterName = parseExp(callExp.Arguments[1]);
return $"{left}:[DISJOINT ${parameterName.Replace("'", "")}]";
}
}
return null;
}
string ParseCallMath()
{
switch (callExp.Method.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,14 @@ public SearchBuilder Dialect(int value)
return this;
}
}

public static class SearchBuilderStringExtensions
{
// 替换为判断field字段是否在以(lon, lat)为圆心,半径为radius的圆内更好,但是只用于Search方法的话还是不用那么复杂的实现了
public static bool GeoRadius(this string field, decimal lon, decimal lat, decimal radius, GeoUnit unit) => true;
public static bool ShapeWithin(this string field, string parameterName) => true;
public static bool ShapeContains(this string field, string parameterName) => true;
public static bool ShapeIntersects(this string field, string parameterName) => true;
public static bool ShapeDisjoint(this string field, string parameterName) => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ public void FtDocumentRepository()
list = repo.Search("@views==200 | @views==300").Dialect(4).ToList();
list = repo.Search("*").Filter("views", 200, 300).Dialect(4).ToList();
list = repo.Search("@location:[-104.800644 38.846127 100 mi]").ToList();
list = repo.Search(a => a.Location.GeoRadius(-104.800644m, 38.846127m, 38.846127m, GeoUnit.mi)).ToList();
list = repo.Search("@shape:[WITHIN $qshape]").Params("qshape", "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))").Dialect(3).ToList();
list = repo.Search(a => a.Shape.ShapeWithin("qshape")).Params("qshape", "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))").Dialect(3).ToList();
}

[Fact]
Expand Down
Loading