diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index 5bd4cd7c..7a7e47af 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -388,26 +388,43 @@ namespace AyaNova.Biz } //ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S + bool NewWordsAdded = false; foreach (string KeyWord in KeyWordList) { if (!ExistingKeywordMatches.ContainsValue(KeyWord)) { ct.SearchDictionary.Add(new SearchDictionary() { Word = KeyWord }); + NewWordsAdded = true; } } //Save the context in order to get the id's of the new words added - ct.SaveChanges(); + if (NewWordsAdded) + ct.SaveChanges(); + + + //----- + //Now add the id's of the newly created words to the matching keyword id list for this object - //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) { bool IsName = false; if (NameKeyWordList.Contains(SD.Word)) IsName = true; - MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = SD.Id, InName = IsName }); - } + //See if it's already in the matching keywordlist or needs to be added + var ExistingMatch = MatchingKeywordIdList.Where(x => x.DictionaryId == SD.Id).FirstOrDefault(); + if (ExistingMatch == null)//If null then needs to be added + MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = SD.Id, InName = IsName }); + else + { + //Not null, but may need to be updated to reflect that it's in the name + if (!ExistingMatch.InName && IsName) + { + ExistingMatch.InName = true; + } + } + } //CREATE THE SEARCHKEY RECORDS FOR ALL THE KEYWORDS foreach (MatchingDictionaryEntry E in MatchingKeywordIdList) @@ -415,6 +432,8 @@ namespace AyaNova.Biz ct.SearchKey.Add(new SearchKey() { WordId = E.DictionaryId, InName = E.InName, ObjectId = objectID, ObjectType = objectType }); } + //--------------------------------- + ct.SaveChanges(); }//eoc diff --git a/test/raven-integration/Search/SearchOps.cs b/test/raven-integration/Search/SearchOps.cs index f0f75076..421f8d95 100644 --- a/test/raven-integration/Search/SearchOps.cs +++ b/test/raven-integration/Search/SearchOps.cs @@ -31,7 +31,7 @@ namespace raven_integration ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString()); Util.ValidateDataReturnResponseOk(a); - long FirstWidgetId = a.ObjectResponse["result"]["id"].Value(); + long MatchFirstWidgetId = a.ObjectResponse["result"]["id"].Value(); //CREATE A SECOND WIDGET D = new JObject(); @@ -43,7 +43,7 @@ namespace raven_integration a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString()); Util.ValidateDataReturnResponseOk(a); - long SecondWidgetId = a.ObjectResponse["result"]["id"].Value(); + long MatchSecondWidgetId = a.ObjectResponse["result"]["id"].Value(); //CREATE A THIRD WIDGET D = new JObject(); @@ -55,7 +55,7 @@ namespace raven_integration a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString()); Util.ValidateDataReturnResponseOk(a); - long ThirdWidgetId = a.ObjectResponse["result"]["id"].Value(); + long NoMatchThirdWidgetId = a.ObjectResponse["result"]["id"].Value(); //Now see if can find that widget with a phrase search dynamic SearchParameters = new JObject();