/// -----------------------------------------------------------------------------
        /// <summary>
        /// UpgradeModule implements the IUpgradeable Interface
        /// </summary>
        /// <param name="version">The current version of the module</param>
        /// -----------------------------------------------------------------------------
        //public string UpgradeModule(string Version)
        //{
        //    throw new System.NotImplementedException("The method or operation is not implemented.");
        //}
        #endregion

        public string UpgradeModule(string version)
        {
            string res = "";

            if (version == "02.01.00")
            {
                var pc = new PortalController();
                foreach (var p in pc.GetPortals().Cast <PortalInfo>())
                {
                    string webConfig = HostingEnvironment.MapPath("~/" + p.HomeDirectory + "/OpenContent/Templates/web.config");
                    res += webConfig;
                    if (File.Exists(webConfig))
                    {
                        res += " : found \n";
                        File.Delete(webConfig);
                        string filename = HostingEnvironment.MapPath("~/DesktopModules/OpenContent/Templates/web.config");
                        File.Copy(filename, webConfig);
                    }
                }
            }
            else if (version == "03.02.00")
            {
                LuceneUtils.IndexAll();
            }
            return(version + res);
        }
Пример #2
0
        private static LuceneQuery HandleFuzzyYngpingQuery(string queryText)
        {
            var queryParser = new MultiFieldQueryParser(LuceneUtils.AppLuceneVersion,
                                                        new string[] { LuceneUtils.Fields.Yngping },
                                                        LuceneUtils.GetAnalyzer(),
                                                        new Dictionary <string, float> {
                { LuceneUtils.Fields.Yngping, 100 },
            });

            return(queryParser.Parse(queryText));
        }
Пример #3
0
        private static void ReIndexIfNeeded(int moduleid, int tabid, int portalId)
        {
            var currentUserCount     = UserController.GetUserCountByPortal(portalId);
            var userCountAtLastIndex = DnnUtils.GetPortalSetting("UserCountAtLastIndex", 0);

            if (currentUserCount != userCountAtLastIndex)
            {
                // reindex module data
                var module = OpenContentModuleConfig.Create(moduleid, tabid, null);
                LuceneUtils.ReIndexModuleData(module);
                DnnUtils.SetPortalSetting("UserCountAtLastIndex", currentUserCount);
                App.Services.Logger.Info("DnnUsers reindexed");
            }
        }
        public void ImportModule(int moduleId, string content, string version, int userId)
        {
            var     module     = OpenContentModuleConfig.Create(moduleId, Null.NullInteger, PortalSettings.Current);
            var     dataSource = new OpenContentDataSource();
            var     dsContext  = OpenContentUtils.CreateDataContext(module, userId);
            XmlNode xml        = Globals.GetContent(content, "opencontent");
            var     items      = xml.SelectNodes("item");

            if (items != null)
            {
                foreach (XmlNode item in items)
                {
                    XmlNode json       = item.SelectSingleNode("json");
                    XmlNode collection = item.SelectSingleNode("collection");
                    XmlNode key        = item.SelectSingleNode("key");
                    try
                    {
                        JToken data = JToken.Parse(json.InnerText);
                        dsContext.Collection = collection?.InnerText ?? "";
                        dataSource.Add(dsContext, data);
                        App.Services.CacheAdapter.SyncronizeCache(module);
                    }
                    catch (Exception e)
                    {
                        App.Services.Logger.Error($"Failed to parse imported json. Item key: {key}. Collection: {collection}. Error: {e.Message}. Stacktrace: {e.StackTrace}");
                        throw;
                    }
                }
            }
            var settings = xml.SelectNodes("moduleSetting");

            if (settings != null)
            {
                foreach (XmlNode setting in settings)
                {
                    XmlNode settingName  = setting.SelectSingleNode("settingName");
                    XmlNode settingValue = setting.SelectSingleNode("settingValue");

                    if (!string.IsNullOrEmpty(settingName?.InnerText))
                    {
                        ModuleController.Instance.UpdateModuleSetting(moduleId, settingName.InnerText, settingValue?.InnerText ?? "");
                    }
                }
            }
            module = OpenContentModuleConfig.Create(moduleId, Null.NullInteger, PortalSettings.Current);

            LuceneUtils.ReIndexModuleData(module);
        }
Пример #5
0
        private void CreateLuceneIndex(YngdiengIndex index)
        {
            var dirInfo = Path.GetFullPath(Path.Join(outputFolder, "lucene"));

            Console.WriteLine($"Writing to {dirInfo}");
            using (var dir = FSDirectory.Open(new DirectoryInfo(dirInfo)))
            {
                var indexConfig = new IndexWriterConfig(LuceneUtils.AppLuceneVersion,
                                                        LuceneUtils.GetAnalyzer());
                using (var writer = new IndexWriter(dir, indexConfig))
                {
                    writer.DeleteAll();
                    foreach (var yDoc in index.YngdiengDocuments)
                    {
                        var doc = new Lucene.Net.Documents.Document {
                            new Int32Field(LuceneUtils.Fields.IsSourceless, yDoc.Sources.Count == 0?1:0, Field.Store.YES),
                            new StringField(LuceneUtils.Fields.DocId, yDoc.DocId, Field.Store.YES),
                            new TextField(LuceneUtils.Fields.Yngping, yDoc.YngpingSandhi, Field.Store.NO),
                            new TextField(LuceneUtils.Fields.Hanzi, yDoc.HanziCanonical.Regular, Field.Store.NO),
                            new StringField(LuceneUtils.Fields.YngpingSandhiTonePattern, GetTonePattern(yDoc.YngpingSandhi), Field.Store.NO)
                        };
                        foreach (var m in yDoc.IndexingExtension.MandarinWords)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Mandarin, m, Field.Store.NO));
                            doc.Add(new TextField(LuceneUtils.Fields.Mandarin, openCcClient.SimplifyMandarinText(m), Field.Store.NO));
                        }
                        foreach (var a in yDoc.HanziAlternatives)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.HanziAlternative, a.Regular, Field.Store.NO));
                        }
                        // Simplify Hanzi for search
                        doc.Add(new TextField(LuceneUtils.Fields.Hanzi, openCcClient.SimplifyHukziuText(yDoc.HanziCanonical.Regular), Field.Store.NO));
                        foreach (var e in yDoc.IndexingExtension.ExplanationText)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Explanation, e, Field.Store.NO));
                        }
                        // TODO: encapsulate this in a YngpingAnalyzer
                        foreach (var yp in yDoc.IndexingExtension.YngpingPermutations)
                        {
                            doc.Add(new TextField(LuceneUtils.Fields.Yngping, yp, Field.Store.NO));
                        }
                        writer.AddDocument(doc);
                    }
                    writer.Flush(triggerMerge: false, applyAllDeletes: false);
                }
            }
        }
Пример #6
0
        private static void ReIndexIfNeeded(int moduleid, int tabid, int portalId)
        {
            if (PortalSettings.Current == null)
            {
                return;                                 // we can not reindex even if we wanted, because we are not in a regular http context (maybe console? scheduler? ashx?)
            }
            var currentUserCount     = UserController.GetUserCountByPortal(portalId);
            var userCountAtLastIndex = DnnUtils.GetPortalSetting("UserCountAtLastIndex", 0);

            if (currentUserCount != userCountAtLastIndex)
            {
                // reindex module data
                var module = OpenContentModuleConfig.Create(moduleid, tabid, null);
                LuceneUtils.ReIndexModuleData(module);
                DnnUtils.SetPortalSetting("UserCountAtLastIndex", currentUserCount);
                App.Services.Logger.Info("DnnUsers reindexed");
            }
        }
Пример #7
0
        private static LuceneQuery HandleHanziQuery(string queryText)
        {
            var queryParser = new MultiFieldQueryParser(
                LuceneUtils.AppLuceneVersion,
                new string[] {
                LuceneUtils.Fields.Mandarin,
                LuceneUtils.Fields.Hanzi,
                LuceneUtils.Fields.HanziAlternative,
                LuceneUtils.Fields.Explanation
            },
                LuceneUtils.GetAnalyzer(),
                new Dictionary <string, float> {
                { LuceneUtils.Fields.Mandarin, 200 },
                { LuceneUtils.Fields.Hanzi, 100 },
                { LuceneUtils.Fields.HanziAlternative, 50 },
                { LuceneUtils.Fields.Explanation, 1 }
            });

            return(queryParser.Parse(queryText));
        }
Пример #8
0
 public override IDataItems GetAll(DataSourceContext context, Select selectQuery)
 {
     ReIndexIfNeeded(context.ModuleId, context.TabId, context.PortalId);
     if (context.Index && selectQuery != null)
     {
         SearchResults docs = LuceneUtils.Search(INDEX_SCOPE, selectQuery);
         if (LogContext.IsLogActive)
         {
             var logKey = "Lucene query";
             LogContext.Log(context.ActiveModuleId, logKey, "Filter", docs.ResultDefinition.Filter);
             LogContext.Log(context.ActiveModuleId, logKey, "Query", docs.ResultDefinition.Query);
             LogContext.Log(context.ActiveModuleId, logKey, "Sort", docs.ResultDefinition.Sort);
             LogContext.Log(context.ActiveModuleId, logKey, "PageIndex", docs.ResultDefinition.PageIndex);
             LogContext.Log(context.ActiveModuleId, logKey, "PageSize", docs.ResultDefinition.PageSize);
         }
         int total    = docs.TotalResults;
         var dataList = new List <IDataItem>();
         foreach (string item in docs.ids)
         {
             var user = UserController.GetUserById(context.PortalId, int.Parse(item));
             if (user != null)
             {
                 dataList.Add(ToData(user));
             }
             else
             {
                 App.Services.Logger.Debug($"DnnUsersDataSource.GetAll() ContentItem not found [{item}]");
             }
         }
         return(new DefaultDataItems()
         {
             Items = dataList,
             Total = total,
             DebugInfo = docs.ResultDefinition.Filter + " - " + docs.ResultDefinition.Query + " - " + docs.ResultDefinition.Sort
         });
     }
     else
     {
         int pageIndex = 0;
         int pageSize  = 1000;
         int total     = 0;
         IEnumerable <UserInfo> users;
         if (selectQuery != null)
         {
             pageIndex = selectQuery.PageIndex;
             pageSize  = selectQuery.PageSize;
             var ruleDisplayName = selectQuery.Query.FilterRules.FirstOrDefault(f => f.Field == "DisplayName");
             var ruleRoles       = selectQuery.Query.FilterRules.FirstOrDefault(f => f.Field == "Roles");
             if (ruleDisplayName != null)
             {
                 string displayName = ruleDisplayName.Value.AsString + "%";
                 users = UserController.GetUsersByDisplayName(context.PortalId, displayName, pageIndex, pageSize, ref total, true, false).Cast <UserInfo>();
             }
             else
             {
                 users = UserController.GetUsers(context.PortalId, pageIndex, pageSize, ref total, true, false).Cast <UserInfo>();
                 total = users.Count();
             }
             if (ruleRoles != null)
             {
                 var roleNames = ruleRoles.MultiValue.Select(r => r.AsString).ToList();
                 users = users.Where(u => u.Roles.Intersect(roleNames).Any());
             }
         }
         else
         {
             users = UserController.GetUsers(context.PortalId, pageIndex, pageSize, ref total, true, false).Cast <UserInfo>();
         }
         int excluded = users.Count() - users.Count(u => u.IsInRole("Administrators"));
         users = users.Where(u => !u.IsInRole("Administrators"));
         //users = users.Skip(pageIndex * pageSize).Take(pageSize);
         var dataList = new List <IDataItem>();
         foreach (var user in users)
         {
             dataList.Add(ToData(user));
         }
         return(new DefaultDataItems()
         {
             Items = dataList,
             Total = total - excluded,
             //DebugInfo =
         });
     }
 }
Пример #9
0
 protected void bIndexAll_Click(object sender, EventArgs e)
 {
     LuceneUtils.IndexAll();
 }
Пример #10
0
        protected void bIndex_Click(object sender, EventArgs e)
        {
            var module = OpenContentModuleConfig.Create(ModuleConfiguration, PortalSettings);

            LuceneUtils.ReIndexModuleData(module);
        }