This commit is contained in:
2018-09-19 15:29:06 +00:00
parent 28275c4206
commit 893971e784
3 changed files with 37 additions and 16 deletions

View File

@@ -35,6 +35,10 @@ IMMEDIATE ITEMS:
- Add code to do actual search and return results and routes (tags need support too as per search specs)
- Add tests for searching and routes
- EventLogProcessor.AddEntry: CHANGE this to save the context itself and then change all callers to handle that (remove save)
- I originally didn't have the save in there because I thought subsequent code might all share in the single context save,
however that's impossible as things like the search indexing require a save to harvest id's so it's not actually saving any time just adding complexity
where it shouldn't (in the caller)
- Auto visible id number assigning code
- Give widgets a visible ID number scheme and add to tests

View File

@@ -210,7 +210,7 @@ namespace AyaNova.Api.Controllers
{
//Log
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes);
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
await ct.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
@@ -287,8 +287,11 @@ namespace AyaNova.Api.Controllers
{
//Log
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Modified), ct);
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes);
await ct.SaveChangesAsync();
//this will save the context as part of it's operations
Search.ProcessUpdatedObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
}
catch (DbUpdateConcurrencyException)
{
@@ -352,9 +355,12 @@ namespace AyaNova.Api.Controllers
//Log now that we have the Id
EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, AyaType.Widget, AyaEvent.Created), ct);
Search.ProcessNewObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes);
await ct.SaveChangesAsync();
//this will save the context as part of it's operations
Search.ProcessNewObjectKeywords(ct, LocaleIdFromContext.Id(HttpContext.Items), o.Id, AyaType.Widget, o.Name, o.Notes, o.Name);
//return success and link
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
}
@@ -406,9 +412,12 @@ namespace AyaNova.Api.Controllers
//Log
EventLogProcessor.DeleteObject(biz.userId, AyaType.Widget, dbObj.Id, dbObj.Name, ct);
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.Widget);
await ct.SaveChangesAsync();
//This will directly execute and is not part of context for saving purposes
Search.ProcessDeletedObjectKeywords(ct, dbObj.Id, AyaType.Widget);
//Delete children / attached objects
biz.DeleteChildren(dbObj);

View File

@@ -44,16 +44,11 @@ namespace AyaNova.Biz
/// <summary>
/// Process the keywords into the dictionary
/// NOTE: NAME parameter is in ADDITION to the NAME also being on of the strings passed in text parameter
/// </summary>
private static void ProcessKeywords(AyContext ct, long localeId, long objectID, AyaType objectType, bool newRecord, string name, params string[] text)
{
//TODO: Code this, using method idea from v7 code and adding the handling of the new InName flag and Name separately.
//Note that as initially coded in widget test class the context will be saved by the controller as it is also done with the event log
//So theoretically I don't save here, but it may turn out that the code requires a save so in that case need to re-do the WidgetController calls to here to
//account for the save
//IF NOT NEW, DELETE ALL EXISTING ENTRIES FOR OBJECT TYPE AND ID
if (!newRecord)
{
@@ -63,6 +58,9 @@ namespace AyaNova.Biz
//BREAK STRING ARRAY INTO KEYWORD LIST
List<string> KeyWordList = Break(localeId, text);
//BREAK NAME STRING
List<string> NameKeyWordList = Break(localeId, name);
//EARLY EXIT IF NO KEYWORDS OR NAME RECORD TO PROCESS
if (KeyWordList.Count == 0 && string.IsNullOrWhiteSpace(name))
{
@@ -88,16 +86,26 @@ namespace AyaNova.Biz
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);
}
//Now add the id's of the newly created words to the matching keyword id list for this object
//OLD BORING WAY:
// foreach (SearchDictionary SD in ct.SearchDictionary.Local)
// {
// MatchingKeywordIdList.Add(SD.Id);
// }
//Linq all the things! (I'm so clever)
MatchingKeywordIdList.AddRange(ct.SearchDictionary.Local.Select(m => m.Id).ToList());
//CREATE THE SEARCHKEY RECORDS FOR ALL THE KEYWORDS
foreach (long KeyWordId in MatchingKeywordIdList)
{
if ()
ct.SearchDictionary.Add(new SearchKey() { Word = KeyWord });
}
}
#endregion