From 39530bf4931a5fb932db85409ed4d863a9ed7105 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 18 Sep 2018 18:08:15 +0000 Subject: [PATCH] --- server/AyaNova/Startup.cs | 8 ++++-- server/AyaNova/biz/LocaleBiz.cs | 9 ++++++ server/AyaNova/biz/Search.cs | 49 +++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 5e6525ce..fa1df9c5 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -337,10 +337,14 @@ namespace AyaNova var ct = context.RequestServices.GetService(); //get the user record - var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, Id = m.Id }).First(); + var u = ct.User.AsNoTracking().Where(a => a.Id == userId).Select(m => new { roles = m.Roles, name = m.Name, id = m.Id, localeId = m.LocaleId }).First(); context.Request.HttpContext.Items["AY_ROLES"] = u.roles; context.Request.HttpContext.Items["AY_USERNAME"] = u.name; - context.Request.HttpContext.Items["AY_USER_ID"] = u.Id; + context.Request.HttpContext.Items["AY_USER_ID"] = u.id; + context.Request.HttpContext.Items["AY_LOCALE_ID"] = u.localeId; + + + } await next.Invoke(); }); diff --git a/server/AyaNova/biz/LocaleBiz.cs b/server/AyaNova/biz/LocaleBiz.cs index 7e9d78d6..a573a850 100644 --- a/server/AyaNova/biz/LocaleBiz.cs +++ b/server/AyaNova/biz/LocaleBiz.cs @@ -339,11 +339,20 @@ namespace AyaNova.Biz return ct.Locale.Any(e => e.Id == id); } + public static bool LocaleExistsStatic(long id, AyContext ct) { return ct.Locale.Any(e => e.Id == id); } + + public static long EnsuredLocaleIdStatic(long id, AyContext ct) + { + if (!ct.Locale.Any(e => e.Id == id)) + return ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID; + return id; + } + public bool LocaleItemExists(long id) { return ct.LocaleItem.Any(e => e.Id == id); diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index e60c12df..a700cfc9 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using Newtonsoft.Json.Linq; using Microsoft.Extensions.Logging; @@ -9,23 +10,17 @@ using AyaNova.Models; namespace AyaNova.Biz { - + //This class handles word breaking, processing keywords and searching for results public static class Search { - // private readonly AyContext ct; - // private readonly ILogger log; - - // public PrimeData(AyContext dbcontext, ILogger logger) - // { - // ct = dbcontext; - // log = logger; - // } - /// /// Process the keywords into the dictionary /// - public static void ProcessKeywords(AyContext ct, long objectID, AyaType objectType, bool newRecord, string keyWords, string name) + public static void ProcessKeywords(AyContext ct, long localeId, long objectID, AyaType objectType, bool newRecord, string keyWords, string name) { + var StopWords = GetStopWords(ct, localeId); + + // //get a db and logger // ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData"); // User u = new User(); @@ -41,14 +36,34 @@ namespace AyaNova.Biz // u.UserOptions=new UserOptions(1); // ct.User.Add(u); // ct.SaveChanges(); - + } - - - - - + private static List GetStopWords(AyContext ct, long localeId) + { + //Get stopwords + //Validate locale id, if not right then use default instead + var Param = new Api.Controllers.LocaleController.LocaleSubsetParam(); + Param.LocaleId = LocaleBiz.EnsuredLocaleIdStatic(localeId, ct); + Param.Keys.Add("StopWords1"); + Param.Keys.Add("StopWords2"); + Param.Keys.Add("StopWords3"); + Param.Keys.Add("StopWords4"); + Param.Keys.Add("StopWords5"); + Param.Keys.Add("StopWords6"); + Param.Keys.Add("StopWords7"); + var Stops = LocaleBiz.GetSubsetStatic(Param).Result; + List StopWords = new List(); + foreach (KeyValuePair kvp in Stops) + { + //Each stopwords locale key is a space delimited list of words and in the case of an empty local string (i.e. StopWords7) it's value is a single question mark + if (kvp.Value != "?") + { + StopWords.AddRange(kvp.Value.Split(" ")); + } + } + return StopWords; + } }//eoc }//eons \ No newline at end of file