// Create functions here. public List <GrantModel> getGrants(FilterModel model) { // Search for specific keywords and dwindle the list down if no matches for a user // chosen filter is found. GetOnlyRelevantGrants(); // Sorts the grant by Score. grants.Sort(); // Then send back the trimmed list. return(grants); // Create local variables here. void GetOnlyRelevantGrants() { // Create variables here. All synonyms gotten from https://www.lexico.com/en/definition/ List <string> grantTypeSearchList = model.GetGrantTypeFilterSearchList(); List <string> locationSearchList = model.GetLocationFilterSearchList(); List <string> raceSearchList = model.GetRaceFilterSearchList(); List <string> religiousAffiliationSearchList = model.GetReligiousAffiliationFilterSearchList(); List <string> grantDueDateSearchList = model.GetGrantDueDateFilterSearchList(); List <string> grantAmountSearchList = model.GetGrantAmountFilterSearchList(); List <string> type501c3SearchList = model.GetType501c3FilterSearchList(); // Traverse the list of grants. foreach (var grant in grants.ToList()) { // Create local variables here. int casList = 0; int gtsList = 0; int lsList = 0; int rsList = 0; int rasList = 0; int gddsList = 0; int gasList = 0; int tcsList = 0; int firsList = 0; int rrrsList = 0; int fddsList = 0; // NOTE: The idea is we increase the corresponding score variable if there's a match. // We remove a grant if the total score is still 0 in the end. if (grantTypeSearchList.Count > 0) { // TODO Might need to adjust education subfilters? Make them essentially another set of filters? foreach (var item in grantTypeSearchList) { gtsList += Regex.Matches(grant.RawText, item, RegexOptions.IgnoreCase).Count; } } if (locationSearchList.Count > 0) { foreach (var item in locationSearchList) { lsList += Regex.Matches(grant.RawText, item, RegexOptions.IgnoreCase).Count; } } if (raceSearchList.Count > 0) { foreach (var item in raceSearchList) { rsList += Regex.Matches(grant.RawText, item, RegexOptions.IgnoreCase).Count; } } if (religiousAffiliationSearchList.Count > 0) { foreach (var item in religiousAffiliationSearchList) { rasList += Regex.Matches(grant.RawText, item, RegexOptions.IgnoreCase).Count; } } if (grantDueDateSearchList.Count > 0) { foreach (var item in grantDueDateSearchList) { gddsList += Regex.Matches(grant.GrantDueDate, item, RegexOptions.IgnoreCase).Count; } } if (grantAmountSearchList.Count > 0) { foreach (var item in grantAmountSearchList) { // Create any variables here. int award = 0; string[] num = item.Split(' '); // Strip all the alphabetic values from the grant amount, then try and parse it. If // it succeeds, store the new value in the award integer. Otherwise, assign -1 to the // award integer. if (!int.TryParse(Regex.Replace(grant.GrantAmount, "[^0-9.]", string.Empty), out award)) { award = -1; } // If the award integer is between the specified brackets, increment the gasList variable. if (num.Length == 2) { if (award >= int.Parse(num[0]) && award < int.Parse(num[1])) { gasList++; } } else if (num.Length == 1) { if (award >= int.Parse(num[0])) { gasList++; } } } } if (type501c3SearchList.Count > 0) { foreach (var item in type501c3SearchList) { tcsList += Regex.Matches(grant.RawText, item, RegexOptions.IgnoreCase).Count; } } // Add up the grant's score. grant.Score = casList + gtsList + lsList + rsList + rasList + gddsList + gasList + tcsList + firsList + rrrsList + fddsList; // If the score is still 0 after the addition, then the grant is unrelated and we remove it. if (grant.Score <= 0) { grants.Remove(grant); } } } }