From e0e5cfada5785419519a4bd82d2140eb4e21217b Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Tue, 4 Oct 2022 18:49:35 -0500 Subject: [PATCH] fix numeric range search queries (#979) --- .../Search/CustomMultiFieldQueryParser.cs | 21 ++++++++++++++++--- .../Search/CustomQueryParser.cs | 20 ++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/ErsatzTV.Infrastructure/Search/CustomMultiFieldQueryParser.cs b/ErsatzTV.Infrastructure/Search/CustomMultiFieldQueryParser.cs index 6c2122b9c..3130bf9c4 100644 --- a/ErsatzTV.Infrastructure/Search/CustomMultiFieldQueryParser.cs +++ b/ErsatzTV.Infrastructure/Search/CustomMultiFieldQueryParser.cs @@ -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); diff --git a/ErsatzTV.Infrastructure/Search/CustomQueryParser.cs b/ErsatzTV.Infrastructure/Search/CustomQueryParser.cs index adf50dd07..d86b4dee7 100644 --- a/ErsatzTV.Infrastructure/Search/CustomQueryParser.cs +++ b/ErsatzTV.Infrastructure/Search/CustomQueryParser.cs @@ -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);