using System; using System.Collections.Generic; using System.IO; using Newtonsoft.Json.Linq; using Microsoft.Extensions.Logging; using AyaNova.Util; using AyaNova.Models; namespace AyaNova.Biz { //This class handles word breaking, processing keywords and searching for results public static class Search { /// /// Process the keywords into the dictionary /// public static void ProcessKeywords(AyContext ct, long localeId, long objectID, AyaType objectType, bool newRecord, string keyWords, string name) { var StopWords = GetStopWords(ct, localeId); //Get CJK index bool flag. //TODO: should this be a property of the locale or a global setting as before?? //if it's a locale property, it could be stored as just another word in the locale dictionary rather than getting into other aspects or maybe it belongs as a bool value on the //locale record itself? // //get a db and logger // ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData"); // User u = new User(); // u.Active=true; // u.Name = "AyaNova Administrator"; // u.Salt = Hasher.GenerateSalt(); // u.Login = "manager"; // u.Password = Hasher.hash(u.Salt, "l3tm3in"); // u.Roles = AuthorizationRoles.BizAdminFull | AuthorizationRoles.OpsAdminFull | AuthorizationRoles.DispatchFull | AuthorizationRoles.InventoryFull; // u.OwnerId = 1; // u.LocaleId=ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first // u.UserType=UserType.Administrator; // u.UserOptions=new UserOptions(1); // ct.User.Add(u); // ct.SaveChanges(); } //Get the current stopwords for the user's locale 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