This commit is contained in:
2018-09-19 22:41:27 +00:00
parent 2988240cef
commit 64d69442a5

View File

@@ -139,45 +139,38 @@ namespace AyaNova.Biz
}
//List holder for matching dictionary ID's
List<long> DictionaryMatches = new List<long>();
//GET LIST OF DICTIONARY ID'S THAT MATCH REGULAR SEARCH TERMS
List<SearchDictionary> RegularMatches = new List<SearchDictionary>();
if (RegularSearchTerms.Count > 0)
RegularMatches = await ct.SearchDictionary.Where(m => RegularSearchTerms.Contains(m.Word)).ToListAsync();
DictionaryMatches = await ct.SearchDictionary.Where(m => RegularSearchTerms.Contains(m.Word)).Select(m => m.Id).ToListAsync();
//GET LIST OF DICTIONARY ID'S THAT MATCH WILDCARD SEARCH TERMS
List<SearchDictionary> WildCardMatches = new List<SearchDictionary>();
//GET LIST OF DICTIONARY ID'S THAT MATCH WILDCARD SEARCH TERMS
if (WildCardSearchTerms.Count > 0)
{
//Ok some fuckery required to implement this the EF CORE way
/*
.Where(entity => entity.Name.Contains("xyz"))
.Where(entity => entity.Name.EndsWith("xyz"))
.Where(entity => entity.Name.StartsWith("xyz"))
*/
foreach (string WildCardSearchTerm in WildCardSearchTerms)
{
//Contains?
if (WildCardSearchTerm.StartsWith("%") && WildCardSearchTerm.EndsWith("%"))
{
WildCardMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).ToListAsync());
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).Select(m => m.Id).ToListAsync());
}
else if (WildCardSearchTerm.EndsWith("%")) //STARTS WITH?
{
WildCardMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).ToListAsync());
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).Select(m => m.Id).ToListAsync());
}
else if (WildCardSearchTerm.StartsWith("%"))//ENDS WITH?
{
WildCardMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).ToListAsync());
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).Select(m => m.Id).ToListAsync());
}
}
WildCardMatches = await ct.SearchDictionary.Where(m => WildCardMatches.Contains(m.Word)).ToListAsync();
}
//SEARCH SEARCHKEY FOR MATCHING WORDS AND OPTIONALLY TYPE AND INNAME
List<SearchKey> SearchKeyMatches = new List<SearchKey>();
SearchKeyMatches = await ct.SearchKey.Where(m => DictionaryMatches.Contains(m.Id)).ToListAsync();
//IF TAGS SPECIFIED
//LOOP THROUGH SEARCHKEY MATCHES