/// <summary>Attemps to parse sort descriptor.</summary> public static bool TryParse(string sortString, out LuceneSort sort) { var match = Regex.Match(sortString, @"^(?<sortDirection>[\\/])?(?<fieldName>.*?)(?:<(?<type>.*?)>)?$"); if (match.Success) { var sortDescending = false; var sortDirectionGroup = match.Groups["sortDirection"]; if (sortDirectionGroup.Success && sortDirectionGroup.Value == "\\") { sortDescending = true; } LuceneType?type = null; var typeGroup = match.Groups["type"]; if (typeGroup.Success) { LuceneType luceneType; if (Enum.TryParse(typeGroup.Value, ignoreCase: true, result: out luceneType)) { type = luceneType; } } sort = new LuceneSort(match.Groups["fieldName"].Value, sortDescending, type); return(true); } sort = null; return(false); }
/// <summary>Attemps to parse sort descriptor.</summary> public static bool TryParse(string sortString, out LuceneSort sort) { var match = Regex.Match(sortString, @"^(?<sortDirection>[\\/])?(?<fieldName>.*?)(?:<(?<type>.*?)>)?$"); if(match.Success) { var sortDescending = false; var sortDirectionGroup = match.Groups["sortDirection"]; if (sortDirectionGroup.Success && sortDirectionGroup.Value == "\\") sortDescending = true; LuceneType? type = null; var typeGroup = match.Groups["type"]; if(typeGroup.Success) { LuceneType luceneType; if (Enum.TryParse(typeGroup.Value, ignoreCase: true, result: out luceneType)) type = luceneType; } sort = new LuceneSort(match.Groups["fieldName"].Value, sortDescending, type); return true; } sort = null; return false; }