From 64d69442a543a97501201e5c8b14c25400c0f169 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 19 Sep 2018 22:41:27 +0000 Subject: [PATCH] --- server/AyaNova/biz/Search.cs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index a87cc299..58a560af 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -139,45 +139,38 @@ namespace AyaNova.Biz } + //List holder for matching dictionary ID's + List DictionaryMatches = new List(); //GET LIST OF DICTIONARY ID'S THAT MATCH REGULAR SEARCH TERMS - List RegularMatches = new List(); 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 WildCardMatches = new List(); + //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 SearchKeyMatches = new List(); + SearchKeyMatches = await ct.SearchKey.Where(m => DictionaryMatches.Contains(m.Id)).ToListAsync(); //IF TAGS SPECIFIED //LOOP THROUGH SEARCHKEY MATCHES