Browse Source

fix numeric range search queries (#979)

pull/980/head
Jason Dove 4 years ago committed by GitHub
parent
commit
e0e5cfada5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      ErsatzTV.Infrastructure/Search/CustomMultiFieldQueryParser.cs
  2. 20
      ErsatzTV.Infrastructure/Search/CustomQueryParser.cs

21
ErsatzTV.Infrastructure/Search/CustomMultiFieldQueryParser.cs

@ -84,10 +84,25 @@ public class CustomMultiFieldQueryParser : MultiFieldQueryParser @@ -84,10 +84,25 @@ public class CustomMultiFieldQueryParser : MultiFieldQueryParser
bool startInclusive,
bool endInclusive)
{
if (CustomQueryParser.NumericFields.Contains(field) && int.TryParse(part1, out int min) &&
int.TryParse(part2, out int max))
if (CustomQueryParser.NumericFields.Contains(field))
{
return NumericRangeQuery.NewInt32Range(field, 1, min, max, startInclusive, endInclusive);
if (part1 is null or "*" && int.TryParse(part2, out int max1))
{
return NumericRangeQuery.NewInt32Range(field, null, max1, startInclusive, endInclusive);
}
if (int.TryParse(part1, out int min))
{
if (part2 is null or "*")
{
return NumericRangeQuery.NewInt32Range(field, min, null, startInclusive, endInclusive);
}
if (int.TryParse(part2, out int max))
{
return NumericRangeQuery.NewInt32Range(field, min, max, startInclusive, endInclusive);
}
}
}
return base.GetRangeQuery(field, part1, part2, startInclusive, endInclusive);

20
ErsatzTV.Infrastructure/Search/CustomQueryParser.cs

@ -91,9 +91,25 @@ public class CustomQueryParser : QueryParser @@ -91,9 +91,25 @@ public class CustomQueryParser : QueryParser
bool startInclusive,
bool endInclusive)
{
if (NumericFields.Contains(field) && int.TryParse(part1, out int min) && int.TryParse(part2, out int max))
if (NumericFields.Contains(field))
{
return NumericRangeQuery.NewInt32Range(field, 1, min, max, startInclusive, endInclusive);
if (part1 is null or "*" && int.TryParse(part2, out int max1))
{
return NumericRangeQuery.NewInt32Range(field, null, max1, startInclusive, endInclusive);
}
if (int.TryParse(part1, out int min))
{
if (part2 is null or "*")
{
return NumericRangeQuery.NewInt32Range(field, min, null, startInclusive, endInclusive);
}
if (int.TryParse(part2, out int max))
{
return NumericRangeQuery.NewInt32Range(field, min, max, startInclusive, endInclusive);
}
}
}
return base.GetRangeQuery(field, part1, part2, startInclusive, endInclusive);

Loading…
Cancel
Save