From 28275c4206b87ba3bbd34655786987c3dcf61f50 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 19 Sep 2018 15:17:14 +0000 Subject: [PATCH] --- server/AyaNova/biz/Search.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index 87b2f41c..02489597 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -69,12 +69,32 @@ namespace AyaNova.Biz return; } - //List MatchingKeywordIdList = new List(); + //BUILD A LIST OF SEARCHDICTIONARY ID'S FOR THE MATCHING WORDS + List MatchingKeywordIdList = new List(); //ITERATE ALL THE KEYWORDS, SEARCH IN THE SEARCHDICTIONARY TABLE AND COLLECT ID'S OF ANY PRE-EXISTING IN DB KEYWORDS - List MatchingKeywordIdList = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).Select(m => m.Id).ToList(); + var ExistingKeywordMatches = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).ToDictionary(m => m.Id, m => m.Word); + //Put the matching keyword ID's into the list + foreach (KeyValuePair K in ExistingKeywordMatches) + { + MatchingKeywordIdList.Add(K.Key); + } //ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S + foreach (string KeyWord in KeyWordList) + { + if (!ExistingKeywordMatches.ContainsValue(KeyWord)) + { + ct.SearchDictionary.Add(new SearchDictionary() { Word = KeyWord }); + } + } + //Save the context in order to get the id's of the new words added + ct.SaveChanges(); + //Now add the id's of the newly created words to the matching keyword id list for this object + foreach (SearchDictionary SD in ct.SearchDictionary.Local) + { + MatchingKeywordIdList.Add(SD.Id); + } //CREATE THE SEARCHKEY RECORDS FOR ALL THE KEYWORDS