// feel free to remove any interfaces that you don't wish to use // (requires that you also update the .dnn manifest file) #region Optional Interfaces /// <summary> /// Gets the modified search documents for the DNN search engine indexer. /// </summary> /// <param name="moduleInfo">The module information.</param> /// <param name="beginDate">The begin date.</param> /// <returns></returns> public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate) { var searchDocuments = new List<SearchDocument>(); var controller = new ItemController(); var items = controller.GetItems(moduleInfo.ModuleID); foreach (var item in items) { if (item.LastModifiedOnDate.ToUniversalTime() <= beginDate.ToUniversalTime() || item.LastModifiedOnDate.ToUniversalTime() >= DateTime.UtcNow) continue; var content = string.Format("{0}<br />{1}", item.ItemName, item.ItemDescription); var searchDocumnet = new SearchDocument { UniqueKey = string.Format("Items:{0}:{1}", moduleInfo.ModuleID, item.ItemId), // any unique identifier to be able to query for your individual record PortalId = moduleInfo.PortalID, // the PortalID TabId = moduleInfo.TabID, // the TabID AuthorUserId = item.LastModifiedByUserId, // the person who created the content Title = moduleInfo.ModuleTitle, // the title of the content, but should be the module title Description = moduleInfo.DesktopModule.Description, // the description or summary of the content Body = content, // the long form of your content ModifiedTimeUtc = item.LastModifiedOnDate.ToUniversalTime(), // a time stamp for the search results page CultureCode = moduleInfo.CultureCode, // the current culture code IsActive = true // allows you to remove the item from the search index (great for soft deletes) }; searchDocuments.Add(searchDocumnet); } return searchDocuments; }
public override IList<SearchDocument> GetModifiedSearchDocuments (ModuleInfo modInfo, DateTime beginDate) { var searchDocs = new List<SearchDocument> (); var settings = new EmployeeListSettingsRepository ().GetSettings (modInfo); IEnumerable<EmployeeInfo> employees = null; using (var modelContext = new UniversityModelContext ()) { employees = new EmployeeQuery (modelContext).ListByDivisionId ( settings.DivisionID, settings.IncludeSubdivisions, settings.SortType); } var now = DateTime.Now; foreach (var employee in employees) { if (employee.LastModifiedOnDate.ToUniversalTime () > beginDate.ToUniversalTime ()) { var aboutEmployee = employee.SearchDocumentText; var sd = new SearchDocument () { PortalId = modInfo.PortalID, AuthorUserId = employee.LastModifiedByUserID, Title = employee.FullName, // Description = HtmlUtils.Shorten (aboutEmployee, 255, "..."), Body = aboutEmployee, ModifiedTimeUtc = employee.LastModifiedOnDate.ToUniversalTime (), UniqueKey = string.Format ("University_Employee_{0}", employee.EmployeeID), Url = string.Format ("/Default.aspx?tabid={0}#{1}", modInfo.TabID, modInfo.ModuleID), IsActive = employee.IsPublished (now) }; searchDocs.Add (sd); } } return searchDocs; }
public override IList<SearchDocument> GetModifiedSearchDocuments (ModuleInfo modInfo, DateTime beginDate) { var searchDocs = new List<SearchDocument> (); var settings = new DivisionSettingsRepository ().GetSettings (modInfo); using (var modelContext = new UniversityModelContext ()) { var division = modelContext.Get<DivisionInfo> (settings.DivisionID); if (division != null && division.LastModifiedOnDate.ToUniversalTime () > beginDate.ToUniversalTime ()) { var aboutDivision = division.SearchDocumentText; var sd = new SearchDocument () { PortalId = modInfo.PortalID, AuthorUserId = division.LastModifiedByUserID, Title = division.Title, // Description = HtmlUtils.Shorten (aboutDivision, 255, "..."), Body = aboutDivision, ModifiedTimeUtc = division.LastModifiedOnDate.ToUniversalTime (), UniqueKey = string.Format ("University_Division_{0}", division.DivisionID), Url = string.Format ("/Default.aspx?tabid={0}#{1}", modInfo.TabID, modInfo.ModuleID), IsActive = division.IsPublished (DateTime.Now) }; searchDocs.Add (sd); } return searchDocs; } }
public override IList<SearchDocument> GetModifiedSearchDocuments (ModuleInfo modInfo, DateTime beginDate) { var searchDocs = new List<SearchDocument> (); var settings = new EmployeeListSettings (modInfo); var employees = GetObjects<EmployeeInfo> (CommandType.StoredProcedure, (settings.IncludeSubdivisions) ? // which SP to use "University_GetRecursiveEmployeesByDivisionID" : "University_GetEmployeesByDivisionID", settings.DivisionID, settings.SortType, false ); foreach (var employee in employees) { if (employee.LastModifiedOnDate.ToUniversalTime () > beginDate.ToUniversalTime ()) { var aboutEmployee = employee.SearchDocumentText; var sd = new SearchDocument () { PortalId = modInfo.PortalID, AuthorUserId = employee.LastModifiedByUserID, Title = employee.FullName, // Description = HtmlUtils.Shorten (aboutEmployee, 255, "..."), Body = aboutEmployee, ModifiedTimeUtc = employee.LastModifiedOnDate.ToUniversalTime (), UniqueKey = string.Format ("University_Employee_{0}", employee.EmployeeID), Url = string.Format ("/Default.aspx?tabid={0}#{1}", modInfo.TabID, modInfo.ModuleID), IsActive = employee.IsPublished }; searchDocs.Add (sd); } } return searchDocs; }
public override IList<SearchDocument> GetModifiedSearchDocuments (ModuleInfo moduleInfo, DateTime beginDate) { var searchDocs = new List<SearchDocument> (); var documents = DocumentsDataProvider.Instance.GetDocuments (moduleInfo.ModuleID, moduleInfo.PortalID); foreach (var document in documents ?? Enumerable.Empty<DocumentInfo> ()) { if (document.ModifiedDate.ToUniversalTime () > beginDate.ToUniversalTime ()) { var documentText = TextUtils.FormatList (" ", document.Title, document.Description); var sd = new SearchDocument () { PortalId = moduleInfo.PortalID, AuthorUserId = document.ModifiedByUserId, Title = document.Title, Description = HtmlUtils.Shorten (documentText, 255, "..."), Body = documentText, ModifiedTimeUtc = document.ModifiedDate.ToUniversalTime (), UniqueKey = string.Format ("Documents_Document_{0}", document.ItemId), IsActive = document.IsPublished, Url = string.Format ("/Default.aspx?tabid={0}#{1}", moduleInfo.TabID, moduleInfo.ModuleID) // FIXME: This one produce null reference exception // Url = Globals.LinkClick (document.Url, moduleInfo.TabID, moduleInfo.ModuleID, document.TrackClicks, document.ForceDownload) }; searchDocs.Add (sd); } } return searchDocs; }
public override IList<SearchDocument> GetModifiedSearchDocuments (ModuleInfo modInfo, DateTime beginDate) { var searchDocs = new List<SearchDocument> (); var settings = new EmployeeSettings (modInfo); var employee = Get<EmployeeInfo> (settings.EmployeeID); if (employee != null && employee.LastModifiedOnDate.ToUniversalTime () > beginDate.ToUniversalTime ()) { var aboutEmployee = employee.SearchDocumentText; var sd = new SearchDocument () { PortalId = modInfo.PortalID, AuthorUserId = employee.LastModifiedByUserID, Title = employee.FullName, // Description = HtmlUtils.Shorten (aboutEmployee, 255, "..."), Body = aboutEmployee, ModifiedTimeUtc = employee.LastModifiedOnDate.ToUniversalTime (), UniqueKey = string.Format ("University_Employee_{0}", employee.EmployeeID), Url = string.Format ("/Default.aspx?tabid={0}#{1}", modInfo.TabID, modInfo.ModuleID), IsActive = employee.IsPublished }; searchDocs.Add (sd); } return searchDocs; }
public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modInfo, DateTime beginDateUtc) { var searchDocuments = new List<SearchDocument>(); OpenContentController ctrl = new OpenContentController(); var content = ctrl.GetFirstContent(modInfo.ModuleID); if (content != null && (content.LastModifiedOnDate.ToUniversalTime() > beginDateUtc && content.LastModifiedOnDate.ToUniversalTime() < DateTime.UtcNow)) { var searchDoc = new SearchDocument { UniqueKey = modInfo.ModuleID.ToString(), PortalId = modInfo.PortalID, Title = modInfo.ModuleTitle, Description = content.Title, Body = content.Json, ModifiedTimeUtc = content.LastModifiedOnDate.ToUniversalTime() }; searchDocuments.Add(searchDoc); } return searchDocuments; }
public override IList<SearchDocument> GetModifiedSearchDocuments (ModuleInfo modInfo, DateTime beginDate) { var searchDocs = new List<SearchDocument> (); var settings = new MiniGallerySettingsRepository ().GetSettings (modInfo); var images = new MiniGalleryDataProvider ().GetImagesTopN (modInfo.ModuleID, false, settings.SortOrder == "SortIndex", settings.NumberOfRecords); foreach (var image in images ?? Enumerable.Empty<ImageInfo>()) { if (image.LastModifiedOnDate.ToUniversalTime () > beginDate.ToUniversalTime ()) { var imageTitle = !string.IsNullOrWhiteSpace (image.Title) ? image.Title : image.Alt; // add only images with text if (!string.IsNullOrWhiteSpace (imageTitle)) { var sd = new SearchDocument () { PortalId = modInfo.PortalID, AuthorUserId = image.LastModifiedByUserID, Title = imageTitle, // Description = HtmlUtils.Shorten (image.Description, 255, "..."), Body = Utils.FormatList (" ", image.Alt, image.Title), ModifiedTimeUtc = image.LastModifiedOnDate.ToUniversalTime (), UniqueKey = string.Format ("MiniGallery_Image_{0}", image.ImageID), Url = string.Format ("/Default.aspx?tabid={0}#{1}", modInfo.TabID, modInfo.ModuleID), IsActive = image.IsPublished }; searchDocs.Add (sd); } } } return searchDocs; }
public void SearchController_Delete_Throws_On_Negative_SearchTypeId() { //Arrange //Act, Assert var searchDoc = new SearchDocument() { UniqueKey = "key", PortalId = 0, SearchTypeId = -1 }; Assert.Throws<ArgumentOutOfRangeException>(() => _internalSearchController.DeleteSearchDocument(searchDoc)); }
public void SearchController_Delete_Throws_On_Null_Or_Empty_UniqueuKey() { //Arrange //Act, Assert var searchDoc = new SearchDocument() { UniqueKey = null, PortalId = 0, SearchTypeId = 1 }; Assert.Throws<ArgumentException>(() => _internalSearchController.DeleteSearchDocument(searchDoc)); }
private void AddSearchDocumentParamters(Document doc, SearchDocument searchDocument, StringBuilder sb) { //mandatory fields doc.Add(new Field(Constants.UniqueKeyTag, StripTagsNoAttributes(searchDocument.UniqueKey, true), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new NumericField(Constants.PortalIdTag, Field.Store.YES, true).SetIntValue(searchDocument.PortalId)); doc.Add(new NumericField(Constants.SearchTypeTag, Field.Store.YES, true).SetIntValue(searchDocument.SearchTypeId)); doc.Add(!string.IsNullOrEmpty(searchDocument.CultureCode) ? new NumericField(Constants.LocaleTag, Field.Store.YES, true).SetIntValue(Localization.Localization.GetCultureLanguageID(searchDocument.CultureCode)) : new NumericField(Constants.LocaleTag, Field.Store.YES, true).SetIntValue(-1)); if (!string.IsNullOrEmpty(searchDocument.Title)) { var field = new Field(Constants.TitleTag, StripTagsRetainAttributes(searchDocument.Title, HtmlAttributesToRetain, false, true), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); if (_titleBoost >0 && _titleBoost != Constants.StandardLuceneBoost) field.Boost = _titleBoost / 10f; doc.Add(field); } if (!string.IsNullOrEmpty(searchDocument.Description)) { var field = new Field(Constants.DescriptionTag, StripTagsRetainAttributes(searchDocument.Description, HtmlAttributesToRetain, false, true), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); if (_descriptionBoost > 0 && _descriptionBoost != Constants.StandardLuceneBoost) field.Boost = _descriptionBoost / 10f; doc.Add(field); } if (!string.IsNullOrEmpty(searchDocument.Body)) { doc.Add(new Field(Constants.BodyTag, StripTagsRetainAttributes(searchDocument.Body, HtmlAttributesToRetain, false, true), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS)); } if (!string.IsNullOrEmpty(searchDocument.Url)) { doc.Add(new Field(Constants.UrlTag, StripTagsNoAttributes(searchDocument.Url, true), Field.Store.YES, Field.Index.NOT_ANALYZED)); } if (!string.IsNullOrEmpty(searchDocument.QueryString)) { doc.Add(new Field(Constants.QueryStringTag, searchDocument.QueryString, Field.Store.YES, Field.Index.NOT_ANALYZED)); } foreach (var kvp in searchDocument.Keywords) { doc.Add(new Field(StripTagsNoAttributes(Constants.KeywordsPrefixTag + kvp.Key, true), StripTagsNoAttributes(kvp.Value, true), Field.Store.YES, Field.Index.NOT_ANALYZED)); sb.Append(StripTagsNoAttributes(kvp.Value, true)).Append(" "); } foreach (var kvp in searchDocument.NumericKeys) { doc.Add(new NumericField(StripTagsNoAttributes(Constants.NumericKeyPrefixTag + kvp.Key, true), Field.Store.YES, true).SetIntValue(kvp.Value)); } foreach (var tag in searchDocument.Tags) { var field = new Field(Constants.Tag, StripTagsNoAttributes(tag.ToLower(), true), Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); if (_tagBoost > 0 && _tagBoost != Constants.StandardLuceneBoost) field.Boost = _tagBoost / 10f; doc.Add(field); } AddIntField(doc, searchDocument.TabId, Constants.TabIdTag); AddIntField(doc, searchDocument.ModuleDefId, Constants.ModuleDefIdTag); AddIntField(doc, searchDocument.ModuleId, Constants.ModuleIdTag); AddIntField(doc, searchDocument.AuthorUserId, Constants.AuthorIdTag); AddIntField(doc, searchDocument.RoleId, Constants.RoleIdTag); if (searchDocument.AuthorUserId > 0) { var user = UserController.Instance.GetUserById(searchDocument.PortalId, searchDocument.AuthorUserId); if (user != null && !string.IsNullOrEmpty(user.DisplayName)) { var field = new Field(Constants.AuthorNameTag, user.DisplayName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); if (_authorBoost > 0 && _authorBoost != Constants.StandardLuceneBoost) field.Boost = _authorBoost / 10f; doc.Add(field); } } if (!string.IsNullOrEmpty(searchDocument.Permissions)) { doc.Add(new Field(Constants.PermissionsTag, StripTagsNoAttributes(searchDocument.Permissions, true), Field.Store.YES, Field.Index.NOT_ANALYZED)); } doc.Add(new NumericField(Constants.ModifiedTimeTag, Field.Store.YES, true).SetLongValue(long.Parse(searchDocument.ModifiedTimeUtc.ToString(Constants.DateTimeFormat)))); if (sb.Length > 0) { var field = new Field(Constants.ContentTag, StripTagsNoAttributes(sb.ToString(), true), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); doc.Add(field); if (_contentBoost > 0 && _contentBoost != Constants.StandardLuceneBoost) field.Boost = _contentBoost/10f; } }
private void DeleteSearchDocumentInternal(SearchDocument searchDocument, bool autoCommit) { var query = new BooleanQuery { {new TermQuery(new Term(Constants.UniqueKeyTag, searchDocument.UniqueKey)), Occur.MUST}, {NumericRangeQuery.NewIntRange(Constants.PortalIdTag, searchDocument.PortalId, searchDocument.PortalId, true, true), Occur.MUST}, {NumericRangeQuery.NewIntRange(Constants.SearchTypeTag, searchDocument.SearchTypeId, searchDocument.SearchTypeId, true, true), Occur.MUST} }; //ModuleCrawler Type if (searchDocument.SearchTypeId == _moduleSearchTypeId) { if (searchDocument.ModuleId > 0) query.Add(NumericRangeQuery.NewIntRange(Constants.ModuleIdTag, searchDocument.ModuleId, searchDocument.ModuleId, true, true), Occur.MUST); query.Add(NumericRangeQuery.NewIntRange(Constants.ModuleDefIdTag, searchDocument.ModuleDefId, searchDocument.ModuleDefId, true, true), Occur.MUST); } LuceneController.Instance.Delete(query); if (autoCommit) { Commit(); } }
public void DeleteSearchDocument(SearchDocument searchDocument) { Requires.NotNullOrEmpty("UniqueKey", searchDocument.UniqueKey); Requires.NotNegative("SearchTypeId", searchDocument.SearchTypeId); Requires.PropertyNotEqualTo("searchDocument", "SearchTypeId", searchDocument.SearchTypeId, 0); DeleteSearchDocumentInternal(searchDocument, false); }
private void AddSearchDocumentInternal(SearchDocument searchDocument, bool autoCommit) { Requires.NotNull("SearchDocument", searchDocument); Requires.NotNullOrEmpty("UniqueKey", searchDocument.UniqueKey); Requires.NotNegative("SearchTypeId", searchDocument.SearchTypeId); Requires.PropertyNotEqualTo("searchDocument", "SearchTypeId", searchDocument.SearchTypeId, 0); Requires.PropertyNotEqualTo("searchDocument", "ModifiedTimeUtc", searchDocument.ModifiedTimeUtc.ToString(CultureInfo.InvariantCulture), DateTime.MinValue.ToString(CultureInfo.InvariantCulture)); if (searchDocument.SearchTypeId == _moduleSearchTypeId) { if(searchDocument.ModuleDefId <= 0) throw new ArgumentException( Localization.Localization.GetExceptionMessage("ModuleDefIdMustBeGreaterThanZero","ModuleDefId must be greater than zero when SearchTypeId is for a module")); if (searchDocument.ModuleId <= 0) throw new ArgumentException(Localization.Localization.GetExceptionMessage("ModuleIdMustBeGreaterThanZero","ModuleId must be greater than zero when SearchTypeId is for a module")); } else { if (searchDocument.ModuleDefId > 0) throw new ArgumentException(Localization.Localization.GetExceptionMessage("ModuleDefIdWhenSearchTypeForModule","ModuleDefId is needed only when SearchTypeId is for a module")); if (searchDocument.ModuleId > 0) throw new ArgumentException(Localization.Localization.GetExceptionMessage("ModuleIdWhenSearchTypeForModule","ModuleId is needed only when SearchTypeId is for a module")); } var doc = new Document(); var sb = new StringBuilder(); //TODO Set setOmitTermFreqAndPositions //TODO Check if Numeric fields need to have Store.YES or Store.NO //TODO - Should ModifiedTime be mandatory //TODO - Is Locale needed for a single-language site //TODO - Sorting //Field.Store.YES | Stores the value. When the value is stored, the original String in its entirety is recorded in the index //Field.Store.NO | Doesn’t store the value. This option is often used along with Index.ANALYZED to index a large text field that doesn’t need to be retrieved // | in its original form, such as bodies of web pages, or any other type of text document. //Index.ANALYZED | Use the analyzer to break the field’s value into a stream of separate tokens and make each token searchable //Index.NOT_ANALYZED | Do index the field, but don’t analyze the String value.Instead, treat the Field’s entire value as a single token and make that token searchable. // Generic and Additional SearchDocument Params AddSearchDocumentParamters(doc, searchDocument, sb); //Remove the existing document from Lucene DeleteSearchDocumentInternal(searchDocument, false); //Add only when Document is active. The previous call would have otherwise deleted the document if it existed earlier if (searchDocument.IsActive) { Thread.SetData(Thread.GetNamedDataSlot(Constants.TlsSearchInfo), searchDocument); try { LuceneController.Instance.Add(doc); } finally { Thread.SetData(Thread.GetNamedDataSlot(Constants.TlsSearchInfo), null); } } if (autoCommit) { Commit(); } }
public void GetSearchResultsBasic() { const string keyword = "awesome"; const string userUrl = "mysite/userid/1"; const string tabUrl1 = "mysite/Home"; const string tabUrl2 = "mysite/AboutUs"; var doc1 = new SearchDocument { UniqueKey = "key01", TabId = TabId1, Url = tabUrl1, Title = keyword, SearchTypeId = TabSearchTypeId, ModifiedTimeUtc = DateTime.UtcNow, RoleId = RoleId731 }; var doc2 = new SearchDocument { UniqueKey = "key02", TabId = TabId2, Url = tabUrl2, Title = keyword, SearchTypeId = TabSearchTypeId, ModifiedTimeUtc = DateTime.UtcNow, RoleId = RoleId0 }; var userdoc = new SearchDocument { UniqueKey = "key03", Url = userUrl, Title = keyword, SearchTypeId = UserSearchTypeId, ModifiedTimeUtc = DateTime.UtcNow, RoleId = RoleId0 }; _internalSearchController.AddSearchDocument(doc1); _internalSearchController.AddSearchDocument(doc2); _internalSearchController.AddSearchDocument(userdoc); var query = new SearchQuery { KeyWords = keyword, PortalIds = new List<int> { PortalId0 }, SearchTypeIds = new[] { ModuleSearchTypeId, TabSearchTypeId, UserSearchTypeId }, ModuleDefIds = new List<int> { HtmlModDefId }, BeginModifiedTimeUtc = DateTime.Now.AddHours(-1.00), EndModifiedTimeUtc = DateTime.Now > DateTime.MinValue ? DateTime.MaxValue : DateTime.MinValue, PageIndex = 1, PageSize = 15, SortField = 0, TitleSnippetLength = 120, BodySnippetLength = 300, CultureCode = CultureEnUs, WildCardSearch = true }; //Run var search = GetGroupBasicViewResults(query); //Assert //Overal 2 groups - tabs and users var groupedBasicViews = search as List<GroupedBasicView> ?? search.ToList(); Assert.AreEqual(2, groupedBasicViews.Count()); //1 User results Assert.AreEqual(1, groupedBasicViews.Single(x=>x.DocumentTypeName=="user").Results.Count()); //User result should have 1 attribute(avatar) Assert.AreEqual(1, groupedBasicViews.Single(x => x.DocumentTypeName == "user").Results.ElementAt(0).Attributes.Count()); //2 Tabs results Assert.AreEqual(2, groupedBasicViews.Single(x => x.DocumentTypeName == "tab").Results.Count()); }
/// ----------------------------------------------------------------------------- /// <summary> /// Returns a collection of SearchDocuments containing module metadata (title, header, footer...) of Searchable Modules. /// </summary> /// <param name="portalId"></param> /// <param name="startDate"></param> /// <returns></returns> /// <history> /// [vnguyen] 05/17/2013 created /// </history> /// ----------------------------------------------------------------------------- public List<SearchDocument> GetModuleMetaData(int portalId, DateTime startDate) { var searchDocuments = new List<SearchDocument>(); var searchModuleCollection = GetSearchModules(portalId, true); foreach (ModuleInfo module in searchModuleCollection) { try { if (module.LastModifiedOnDate > startDate && module.LastModifiedOnDate < DateTime.Now) { var searchDoc = new SearchDocument { SearchTypeId = ModuleSearchTypeId, UniqueKey = Constants.ModuleMetaDataPrefixTag + module.ModuleID, ModuleDefId = module.ModuleDefID, ModuleId = module.ModuleID, Title = module.ModuleTitle, PortalId = portalId, CultureCode = module.CultureCode, ModifiedTimeUtc = module.LastModifiedOnDate, Body = module.Header + " " + module.Footer }; if (module.Terms != null && module.Terms.Count > 0) { searchDoc.Tags = module.Terms.Select(t => t.Name); } Logger.Trace("ModuleIndexer: Search document for metaData found for module [" + module.DesktopModule.ModuleName + " mid:" + module.ModuleID + "]"); searchDocuments.Add(searchDoc); } } catch (Exception ex) { Exceptions.Exceptions.LogException(ex); } } return searchDocuments; }
private void AddBasicInformation(Dictionary<string, SearchDocument> searchDocuments, List<int> indexedUsers, UserSearch userSearch, int portalId) { if (!searchDocuments.ContainsKey( string.Format("{0}_{1}", userSearch.UserId, UserVisibilityMode.AllUsers) .ToLowerInvariant())) { if (!indexedUsers.Contains(userSearch.UserId)) { indexedUsers.Add(userSearch.UserId); } //if the user doesn't exist in search collection, we need add it with ALLUsers mode, //so that can make sure DisplayName will be indexed var searchDoc = new SearchDocument { SearchTypeId = UserSearchTypeId, UniqueKey = string.Format("{0}_{1}", userSearch.UserId, UserVisibilityMode.AllUsers).ToLowerInvariant(), PortalId = portalId, ModifiedTimeUtc = userSearch.LastModifiedOnDate, Body = string.Empty, Description = userSearch.FirstName, Title = userSearch.DisplayName }; //searchDoc.NumericKeys.Add("superuser", Convert.ToInt32(userSearch.SuperUser)); searchDocuments.Add(searchDoc.UniqueKey, searchDoc); } if (!searchDocuments.ContainsKey( string.Format("{0}_{1}", userSearch.UserId, UserVisibilityMode.AdminOnly) .ToLowerInvariant())) { if (!indexedUsers.Contains(userSearch.UserId)) { indexedUsers.Add(userSearch.UserId); } //if the user doesn't exist in search collection, we need add it with ALLUsers mode, //so that can make sure DisplayName will be indexed var searchDoc = new SearchDocument { SearchTypeId = UserSearchTypeId, UniqueKey = string.Format("{0}_{1}", userSearch.UserId, UserVisibilityMode.AdminOnly).ToLowerInvariant(), PortalId = portalId, ModifiedTimeUtc = userSearch.LastModifiedOnDate, Body = string.Empty, Description = userSearch.FirstName, Title = userSearch.DisplayName }; searchDoc.NumericKeys.Add("superuser", Convert.ToInt32(userSearch.SuperUser)); searchDoc.Keywords.Add("username", userSearch.UserName); searchDoc.Keywords.Add("email", userSearch.Email); searchDoc.Keywords.Add("createdondate", userSearch.CreatedOnDate.ToString(Constants.DateTimeFormat)); searchDocuments.Add(searchDoc.UniqueKey, searchDoc); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Returns the collection of SearchDocuments populated with Tab MetaData for the given portal. /// </summary> /// <param name="portalId"></param> /// <param name="startDate"></param> /// <returns></returns> /// <history> /// [vnguyen] 04/16/2013 created /// </history> /// ----------------------------------------------------------------------------- public override IEnumerable<SearchDocument> GetSearchDocuments(int portalId, DateTime startDate) { var searchDocuments = new Dictionary<string, SearchDocument>(); var needReindex = PortalController.GetPortalSettingAsBoolean(UserIndexResetFlag, portalId, false); if (needReindex) { startDate = SqlDateTime.MinValue.Value; } try { var startUserId = Null.NullInteger; while (true) { var reader = DataProvider.Instance().GetAvailableUsersForIndex(portalId, startDate, startUserId, BatchSize); int rowsAffected = 0; var indexedUsers = new List<int>(); while (reader.Read()) { var userId = Convert.ToInt32(reader["UserId"]); var displayName = reader["DisplayName"].ToString(); var firstName = reader["FirstName"].ToString(); var propertyName = reader["PropertyName"].ToString(); var propertyValue = reader["PropertyValue"].ToString(); var visibilityMode = ((UserVisibilityMode) Convert.ToInt32(reader["Visibility"])); var modifiedTime = Convert.ToDateTime(reader["ModifiedTime"]).ToUniversalTime(); //log the userid so that it can get the correct user collection next time. if (userId > startUserId) { startUserId = userId; } var uniqueKey = string.Format("{0}_{1}", userId, visibilityMode).ToLowerInvariant(); if (visibilityMode == UserVisibilityMode.FriendsAndGroups) { uniqueKey = string.Format("{0}_{1}", uniqueKey, reader["ExtendedVisibility"]); } if (searchDocuments.ContainsKey(uniqueKey)) { var document = searchDocuments[uniqueKey]; document.Body += string.Format(" {0}", propertyValue); if (modifiedTime > document.ModifiedTimeUtc) { document.ModifiedTimeUtc = modifiedTime; } } else { //Need remove use exists index for all visibilities. if(!indexedUsers.Contains(userId)) { indexedUsers.Add(userId); } if (!string.IsNullOrEmpty(propertyValue)) { var searchDoc = new SearchDocument { SearchTypeId = UserSearchTypeId, UniqueKey = uniqueKey, PortalId = portalId, ModifiedTimeUtc = modifiedTime, Body = propertyValue, Description = firstName, Title = displayName }; searchDocuments.Add(uniqueKey, searchDoc); } else if (!searchDocuments.ContainsKey(string.Format("{0}_{1}", userId, UserVisibilityMode.AllUsers).ToLowerInvariant())) { if (!indexedUsers.Contains(userId)) { indexedUsers.Add(userId); } //if the user doesn't exist in search collection, we need add it with ALLUsers mode, //so that can make sure DisplayName will be indexed var searchDoc = new SearchDocument { SearchTypeId = UserSearchTypeId, UniqueKey = string.Format("{0}_{1}", userId, UserVisibilityMode.AllUsers).ToLowerInvariant(), PortalId = portalId, ModifiedTimeUtc = modifiedTime, Body = string.Empty, Description = firstName, Title = displayName }; searchDocuments.Add(searchDoc.UniqueKey, searchDoc); } } rowsAffected++; } //close the data reader reader.Close(); //remov exists indexes DeleteDocuments(portalId, indexedUsers); if (rowsAffected == 0) { break; } } if (needReindex) { PortalController.DeletePortalSetting(portalId, UserIndexResetFlag); } } catch (Exception ex) { Exceptions.Exceptions.LogException(ex); } return searchDocuments.Values; }
public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modInfo, DateTime beginDate) { string partition = (string)modInfo.ModuleSettings["Partitioning"]; int partModuleId = -1; int partPortalId = -1; switch (partition) { case "1": partModuleId = modInfo.ModuleID; break; case "2": partPortalId = modInfo.PortalID; break; case "3": partPortalId = modInfo.PortalID; partModuleId = modInfo.ModuleID; break; } var searchDocuments = new List<SearchDocument>(); LocaleController lc = new LocaleController(); Dictionary<string, Locale> loc = lc.GetLocales(modInfo.PortalID); foreach (KeyValuePair<string, Locale> item in loc) { string cultureCode = item.Value.Culture.Name; List<StoryInfo> stories = DbController.Instance.GetStories(partModuleId, partPortalId, "STORY", cultureCode, false).ToList(); foreach (StoryInfo story in stories) { DateTime lastmodified = ((DateTime)story.LastModifiedOnDate).ToUniversalTime(); if (lastmodified > beginDate.ToUniversalTime() && lastmodified < DateTime.UtcNow) { var strContent = HtmlUtils.Clean(story.Story, false); // Get the description string var description = strContent.Length <= 500 ? strContent : HtmlUtils.Shorten(strContent, 500, "..."); var searchDoc = new SearchDocument { UniqueKey = story.StoryId.ToString(), PortalId = modInfo.PortalID, ModuleId = modInfo.ModuleID, ModuleDefId = modInfo.ModuleDefID, Title = story.Title, Description = description, Body = strContent, ModifiedTimeUtc = lastmodified, AuthorUserId = (story.CreatedByUserID ?? -1), CultureCode = cultureCode, IsActive = (story.StartDate == null || story.StartDate < DateTime.Now) && (story.EndDate == null || story.EndDate + new TimeSpan(1, 0, 0, 0) >= DateTime.Now), SearchTypeId = 1, QueryString = "#view/"+story.StoryId.ToString() }; if (modInfo.Terms != null && modInfo.Terms.Count > 0) { searchDoc.Tags = CollectHierarchicalTags(modInfo.Terms); } searchDocuments.Add(searchDoc); } } } return searchDocuments; }
public void SearchController_Add_Then_Delete_Portals_WorksAsExpected() { //Arrange const int totalDocs = 10; // must be even var now = DateTime.UtcNow; //Act for (var i = 1; i <= totalDocs; i++) { var doc = new SearchDocument { PortalId = i <= (totalDocs/2) ? PortalId0 : PortalId1, UniqueKey = Guid.NewGuid().ToString(), SearchTypeId = ModuleSearchTypeId, ModifiedTimeUtc = now, ModuleId = 100, ModuleDefId = 10, }; _internalSearchController.AddSearchDocument(doc); } //Assert var stats = GetSearchStatistics(); Assert.AreEqual(totalDocs, stats.TotalActiveDocuments); //Act - delete all portal 1 items var searchDoc = new SearchDocument {PortalId = PortalId1}; _internalSearchController.DeleteSearchDocument(searchDoc); //Assert - delete all portal 1 stats = GetSearchStatistics(); Assert.AreEqual(totalDocs/2, stats.TotalActiveDocuments); Assert.AreEqual(totalDocs/2, stats.TotalDeletedDocuments); }
private String DoProductIdx(DotNetNuke.Entities.Portals.PortalInfo portal, DateTime lastrun, Boolean debug) { if (debug) { InternalSearchController.Instance.DeleteAllDocuments(portal.PortalID, SearchHelper.Instance.GetSearchTypeByName("tab").SearchTypeId); } var searchDocs = new List<SearchDocument>(); var culturecodeList = DnnUtils.GetCultureCodeList(portal.PortalID); var storeSettings = new StoreSettings(portal.PortalID); foreach (var lang in culturecodeList) { var strContent = ""; // select all products var objCtrl = new NBrightBuyController(); var strFilter = " and NB1.ModifiedDate > convert(datetime,'" + lastrun.ToString("s") + "') "; if (debug) strFilter = ""; var l = objCtrl.GetList(portal.PortalID, -1, "PRD", strFilter); foreach (var p in l) { var prodData = new ProductData(p.ItemID, lang); strContent = prodData.Info.GetXmlProperty("genxml/textbox/txtproductref") + " : " + prodData.SEODescription + " " + prodData.SEOName + " " + prodData.SEOTagwords + " " + prodData.SEOTitle; if (strContent != "") { var tags = new List<String>(); tags.Add("nbsproduct"); //Get the description string string strDescription = HtmlUtils.Shorten(HtmlUtils.Clean(strContent, false), 100, "..."); var searchDoc = new SearchDocument(); // Assigns as a Search key the SearchItems' searchDoc.UniqueKey = prodData.Info.ItemID.ToString(""); searchDoc.QueryString = "ref=" + prodData.Info.GetXmlProperty("genxml/textbox/txtproductref"); searchDoc.Title = prodData.ProductName; searchDoc.Body = strContent; searchDoc.Description = strDescription; if (debug) searchDoc.ModifiedTimeUtc = DateTime.Now.Date; else searchDoc.ModifiedTimeUtc = prodData.Info.ModifiedDate; searchDoc.AuthorUserId = 1; searchDoc.TabId = storeSettings.ProductDetailTabId; searchDoc.PortalId = portal.PortalID; searchDoc.SearchTypeId = SearchHelper.Instance.GetSearchTypeByName("tab").SearchTypeId; searchDoc.CultureCode = lang; searchDoc.Tags = tags; //Add Module MetaData searchDoc.ModuleDefId = 0; searchDoc.ModuleId = 0; searchDocs.Add(searchDoc); } } } //Index InternalSearchController.Instance.AddSearchDocuments(searchDocs); InternalSearchController.Instance.Commit(); return " - NBS-DNNIDX scheduler ACTIVATED "; }
public void SearchController_Add_Then_Delete_Users_WorksAsExpected() { //Arrange const int totalDocs = 10; var now = DateTime.UtcNow; //Act for (var i = 1; i <= totalDocs; i++) { var doc = new SearchDocument { AuthorUserId = i, PortalId = PortalId0, UniqueKey = Guid.NewGuid().ToString(), SearchTypeId = ModuleSearchTypeId, ModifiedTimeUtc = now, ModuleId = 100, ModuleDefId = 10, }; _internalSearchController.AddSearchDocument(doc); } //Assert var stats = GetSearchStatistics(); Assert.AreEqual(totalDocs, stats.TotalActiveDocuments); //Act - delete last item var searchDoc = new SearchDocument {AuthorUserId = totalDocs}; _internalSearchController.DeleteSearchDocument(searchDoc); //Assert stats = GetSearchStatistics(); Assert.AreEqual(totalDocs - 1, stats.TotalActiveDocuments); Assert.AreEqual(1, stats.TotalDeletedDocuments); //Act - delete first item searchDoc = new SearchDocument {AuthorUserId = 1}; _internalSearchController.DeleteSearchDocument(searchDoc); //Assert stats = GetSearchStatistics(); Assert.AreEqual(totalDocs - 2, stats.TotalActiveDocuments); Assert.AreEqual(2, stats.TotalDeletedDocuments); }
public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate) { var searchDocuments = new Dictionary<string, SearchDocument>(); int lastJournalId = Null.NullInteger; if (beginDate == DateTime.MinValue) { beginDate = SqlDateTime.MinValue.Value; } if (beginDate > SqlDateTime.MinValue.Value) { beginDate = beginDate.ToUniversalTime(); } try { while (true) { var reader = DataProvider.Instance() .ExecuteReader("Journal_GetSearchItems", moduleInfo.PortalID, moduleInfo.TabModuleID, beginDate, lastJournalId, Constants.SearchBatchSize); var journalIds = new Dictionary<int, int>(); while (reader.Read()) { var journalId = Convert.ToInt32(reader["JournalId"]); var journalTypeId = reader["JournalTypeId"].ToString(); var userId = Convert.ToInt32(reader["UserId"]); var dateUpdated = Convert.ToDateTime(reader["DateUpdated"]); var profileId = reader["ProfileId"].ToString(); var groupId = reader["GroupId"].ToString(); var title = reader["Title"].ToString(); var summary = reader["Summary"].ToString(); var securityKey = reader["SecurityKey"].ToString(); var tabId = reader["TabId"].ToString(); var tabModuleId = reader["ModuleId"].ToString(); var key = string.Format("JI_{0}", journalId); if (searchDocuments.ContainsKey(key)) { searchDocuments[key].UniqueKey += string.Format(",{0}", securityKey); } else { var searchDocument = new SearchDocument() { UniqueKey = string.Format("JI_{0}_{1}", journalId, securityKey), Body = summary, ModifiedTimeUtc = dateUpdated, Title = title, AuthorUserId = userId, Keywords = new Dictionary<string, string>() { {"TabId", tabId}, {"TabModuleId", tabModuleId}, {"ProfileId", profileId}, {"GroupId", groupId} } }; searchDocuments.Add(key, searchDocument); } if (journalId > lastJournalId) { lastJournalId = journalId; } if (!journalIds.ContainsKey(journalId)) { journalIds.Add(journalId, userId); } } //close the reader reader.Close(); if (journalIds.Count == 0) { break; } else { //index comments for this journal AddCommentItems(journalIds, searchDocuments); } } } catch (Exception ex) { Exceptions.LogException(ex); } return searchDocuments.Values.ToList(); }
public override IList<DotNetNuke.Services.Search.Entities.SearchDocument> GetModifiedSearchDocuments(ModuleInfo moduleInfo, DateTime beginDate) { //create search item collection var searchItemColl = new List<SearchDocument>();// SearchItemInfoCollection(); //get list of items by moduleID FileController ctrlFiles = new FileController(); foreach (File file in ctrlFiles.GetSearchableItems(beginDate)) { //SearchItemInfo sii = new SearchItemInfo(); SearchDocument sii = new SearchDocument(); string strContent; string strGUID; string strDescription; switch (file.ItemType) { case 1: //file strContent = String.Format("{0} {1} {2} {3} {4}", file.Name, file.Description, file.CreatedByUserName, file.LastModifiedByUserName, file.FileType); strGUID = "Open=" + file.ID.ToString(); var parentFile = ctrlFiles.Get(file.ParentID); int parentID = parentFile.ID; if (parentFile.ItemType != 0) { parentID = parentFile.ParentID; } strDescription = file.Description;// String.Format("<a href=\"{0}\">[Open Containing Folder]</a> {1}", Globals.NavigateURL(moduleInfo.TabID, "", "Folder=" + parentID.ToString()), file.Description); break; case 2: //hyperlink strContent = String.Format("{0} {1} {2} {3} {4}", file.Name, file.Description, file.CreatedByUserName, file.LastModifiedByUserName, file.FileType); strGUID = "Open=" + file.ID.ToString(); strDescription = file.Description;// String.Format("<a href=\"{0}\">[Open Containing Folder]</a> {1}", Globals.NavigateURL(moduleInfo.TabID, "", "Folder=" + file.ParentID.ToString()), file.Description); break; default: //folder strContent = String.Format("{0} {1} {2} {3} {4}", file.Name, file.Description, file.CreatedByUserName, file.LastModifiedByUserName, file.FileType); strGUID = "Folder=" + file.ID.ToString(); strDescription = file.Description; break; } //get see permissions PermissionController ctrlPerm = new PermissionController(); var perms = ctrlPerm.GetItems(file.ID); string strPerms = ""; foreach (Permission perm in perms) { if (perm.CanSee) { if (perm.UserID != 0) { //user perm strPerms += String.Format("[{0}];", perm.UserID); } else { //role perm if (perm.RoleName == "All Users") { strPerms = ""; break; } strPerms += perm.RoleName; } } } if (strPerms.Length > 0) { strPerms = strPerms.Substring(0, strPerms.Length - 1); } sii.AuthorUserId = file.LastModifiedByUserID; sii.ModuleId = file.ModuleID; sii.Body = strContent; //sii.CultureCode = ""; sii.Description = strDescription; sii.IsActive = true; //sii.Keywords = strContent; sii.ModifiedTimeUtc = file.LastModifiedDate; sii.ModuleDefId = moduleInfo.ModuleDefID; sii.ModuleId = file.ModuleID; //sii.NumericKeys = ""; sii.Permissions = strPerms; sii.PortalId = file.PortalID; sii.QueryString = strGUID; //sii.RoleId = -1; //sii.SearchTypeId = -1; sii.TabId = moduleInfo.TabID; //sii.Tags = ""; sii.Title = file.Name; sii.UniqueKey = file.ID.ToString(); //sii.Url = ""; /* sii.PubDate = file.CreatedDate; sii.Description = strDescription; sii.SearchItemId = file.ID; sii.Content = strContent; sii.SearchKey = file.ID.ToString(); sii.GUID = strGUID; sii.TabId = ModInfo.TabID; sii.Title = file.Name; */ searchItemColl.Add(sii); } return searchItemColl; }
public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modInfo, DateTime beginDate) { var workflowId = GetWorkflow(modInfo.ModuleID, modInfo.TabID, modInfo.PortalID).Value; var searchDocuments = new List<SearchDocument>(); var htmlTextInfo = GetTopHtmlText(modInfo.ModuleID, true, workflowId); if (htmlTextInfo != null && (htmlTextInfo.LastModifiedOnDate.ToUniversalTime() > beginDate.ToUniversalTime() && htmlTextInfo.LastModifiedOnDate.ToUniversalTime() < DateTime.UtcNow)) { var strContent = HtmlUtils.Clean(htmlTextInfo.Content, false); // Get the description string int maxLength; if (!Int32.TryParse((string)modInfo.ModuleSettings["HtmlText_SearchDescLength"], out maxLength)) { maxLength = MAX_DESCRIPTION_LENGTH; } var description = strContent.Length <= maxLength ? strContent : HtmlUtils.Shorten(strContent, maxLength, "..."); var searchDoc = new SearchDocument { UniqueKey = modInfo.ModuleID.ToString(), PortalId = modInfo.PortalID, Title = modInfo.ModuleTitle, Description = description, Body = strContent, ModifiedTimeUtc = htmlTextInfo.LastModifiedOnDate.ToUniversalTime() }; if (modInfo.Terms != null && modInfo.Terms.Count > 0) { searchDoc.Tags = CollectHierarchicalTags(modInfo.Terms); } searchDocuments.Add(searchDoc); } return searchDocuments; }
public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modInfo, DateTime beginDate) { var searchDocuments = new List<SearchDocument>(); var FAQs = ListFAQ(Convert.ToInt32(modInfo.ModuleID), 0, true); foreach (object objFaq in FAQs) { var faq = ((FAQsInfo)objFaq); if (faq.FaqHide) continue; // Remove all HTML overhead from the content string strContent = HtmlUtils.Clean(faq.Answer, false); // And create an entry that will fit string strDescription = HtmlUtils.Clean(faq.Question, false); strDescription = strDescription.Length <= MAX_DESCRIPTION_LENGTH ? strDescription : HtmlUtils.Shorten(strDescription, 100, "..."); var searchDoc = new SearchDocument { UniqueKey = String.Format("faqid={0}", faq.ItemID), PortalId = modInfo.PortalID, Title = modInfo.ModuleTitle, Description = strDescription, Body = strContent, ModifiedTimeUtc = DateTime.Now.ToUniversalTime() // faq.DateModified.ToUniversalTime() }; searchDocuments.Add(searchDoc); } return searchDocuments; }
/// ----------------------------------------------------------------------------- /// <summary> /// Returns the collection of SearchDocuments populated with Tab MetaData for the given portal. /// </summary> /// <param name="portalId"></param> /// <param name="startDateLocal"></param> /// <returns></returns> /// <history> /// [vnguyen] 04/16/2013 created /// </history> /// ----------------------------------------------------------------------------- public override IEnumerable<SearchDocument> GetSearchDocuments(int portalId, DateTime startDateLocal) { var searchDocuments = new Dictionary<string, SearchDocument>(); var needReindex = PortalController.GetPortalSettingAsBoolean(UserIndexResetFlag, portalId, false); if (needReindex) { startDateLocal = SqlDateTime.MinValue.Value.AddDays(1); } var controller = new ListController(); var textDataType = controller.GetListEntryInfo("DataType", "Text"); var richTextDataType = controller.GetListEntryInfo("DataType", "RichText"); var profileDefinitions = ProfileController.GetPropertyDefinitionsByPortal(portalId, false, false) .Cast<ProfilePropertyDefinition>() .Where(d => (textDataType != null && d.DataType == textDataType.EntryID) || (richTextDataType != null && d.DataType == richTextDataType.EntryID)).ToList(); try { var startUserId = Null.NullInteger; while (true) { var reader = DataProvider.Instance() .GetAvailableUsersForIndex(portalId, startDateLocal, startUserId, BatchSize); int rowsAffected = 0; var indexedUsers = new List<int>(); while (reader.Read()) { var userSearch = GetUserSearch(reader); AddBasicInformation(searchDocuments, indexedUsers, userSearch, portalId); //log the userid so that it can get the correct user collection next time. if (userSearch.UserId > startUserId) { startUserId = userSearch.UserId; } foreach (var definition in profileDefinitions) { var propertyName = definition.PropertyName; if (!ContainsColumn(propertyName, reader)) { continue; } var propertyValue = reader[propertyName].ToString(); if (string.IsNullOrEmpty(propertyValue) || !propertyValue.Contains(ValueSplitFlag)) { continue; } var splitValues = Regex.Split(propertyValue, Regex.Escape(ValueSplitFlag)); propertyValue = splitValues[0]; var visibilityMode = ((UserVisibilityMode) Convert.ToInt32(splitValues[1])); var extendedVisibility = splitValues[2]; var modifiedTime = Convert.ToDateTime(splitValues[3]).ToUniversalTime(); if (string.IsNullOrEmpty(propertyValue)) { continue; } var uniqueKey = string.Format("{0}_{1}", userSearch.UserId, visibilityMode).ToLowerInvariant(); if (visibilityMode == UserVisibilityMode.FriendsAndGroups) { uniqueKey = string.Format("{0}_{1}", uniqueKey, extendedVisibility); } if (searchDocuments.ContainsKey(uniqueKey)) { var document = searchDocuments[uniqueKey]; document.Keywords.Add(propertyName, propertyValue); if (modifiedTime > document.ModifiedTimeUtc) { document.ModifiedTimeUtc = modifiedTime; } } else { //Need remove use exists index for all visibilities. if (!indexedUsers.Contains(userSearch.UserId)) { indexedUsers.Add(userSearch.UserId); } if (!string.IsNullOrEmpty(propertyValue)) { var searchDoc = new SearchDocument { SearchTypeId = UserSearchTypeId, UniqueKey = uniqueKey, PortalId = portalId, ModifiedTimeUtc = modifiedTime, Description = userSearch.FirstName, Title = userSearch.DisplayName }; searchDoc.Keywords.Add(propertyName, propertyValue); searchDoc.NumericKeys.Add("superuser", Convert.ToInt32(userSearch.SuperUser)); searchDocuments.Add(uniqueKey, searchDoc); } } } rowsAffected++; } //close the data reader reader.Close(); //remov exists indexes DeleteDocuments(portalId, indexedUsers); if (rowsAffected == 0) { break; } } if (needReindex) { PortalController.DeletePortalSetting(portalId, UserIndexResetFlag); } } catch (Exception ex) { Exceptions.Exceptions.LogException(ex); } return searchDocuments.Values; }
/// ----------------------------------------------------------------------------- /// <summary> /// Returns the collection of SearchDocuments populated with Tab MetaData for the given portal. /// </summary> /// <param name="portalId"></param> /// <param name="startDate"></param> /// <returns></returns> /// <history> /// [vnguyen] 04/16/2013 created /// </history> /// ----------------------------------------------------------------------------- public override IEnumerable<SearchDocument> GetSearchDocuments(int portalId, DateTime startDate) { var searchDocuments = new List<SearchDocument>(); var tabController = new TabController(); var tabs = tabController.GetTabsByPortal(portalId).AsList().Where(t => ((t.TabSettings["AllowIndex"] == null) || (t.TabSettings["AllowIndex"] != null && t.TabSettings["AllowIndex"].ToString().ToLower() != "false")) && t.LastModifiedOnDate > startDate); try { foreach (var tab in tabs) { var searchDoc = new SearchDocument { SearchTypeId = TabSearchTypeId, UniqueKey = Constants.TabMetaDataPrefixTag + tab.TabID, TabId = tab.TabID, PortalId = tab.PortalID, CultureCode = tab.CultureCode, ModifiedTimeUtc = tab.LastModifiedOnDate, Body = tab.PageHeadText, Description = tab.Description }; searchDoc.Keywords.Add("keywords", tab.KeyWords); //Using TabName for searchDoc.Title due to higher prevalence and relavency || TabTitle will be stored as a keyword searchDoc.Title = tab.TabName; searchDoc.Keywords.Add("title", tab.Title); if (tab.Terms != null && tab.Terms.Count > 0) { searchDoc.Tags = tab.Terms.Select(t => t.Name); } Logger.Trace("TabIndexer: Search document for metaData added for page [" + tab.Title + " tid:" + tab.TabID + "]"); searchDocuments.Add(searchDoc); } } catch (Exception ex) { Exceptions.Exceptions.LogException(ex); } return searchDocuments; }
/// ----------------------------------------------------------------------------- /// <summary> /// Converts a SearchItemInfo into a SearchDocument. /// /// SearchItemInfo object was used in the old version of search. /// </summary> /// <param name="searchItem"></param> /// <returns></returns> /// <history> /// [vnguyen] 05/16/2013 created /// </history> /// ----------------------------------------------------------------------------- #pragma warning disable 0618 public SearchDocument ConvertSearchItemInfoToSearchDocument(SearchItemInfo searchItem) { var moduleController = new ModuleController(); var module = moduleController.GetModule(searchItem.ModuleId); var searchDoc = new SearchDocument { // Assigns as a Search key the SearchItems' GUID, if not it creates a dummy guid. UniqueKey = (searchItem.SearchKey.Trim() != string.Empty) ? searchItem.SearchKey : Guid.NewGuid().ToString(), QueryString = searchItem.GUID, Title = searchItem.Title, Body = searchItem.Content, Description = searchItem.Description, ModifiedTimeUtc = searchItem.PubDate, AuthorUserId = searchItem.Author, TabId = searchItem.TabId, PortalId = module.PortalID, SearchTypeId = ModuleSearchTypeId, CultureCode = module.CultureCode, //Add Module MetaData ModuleDefId = module.ModuleDefID, ModuleId = module.ModuleID }; return searchDoc; }
public void AddSearchDocument(SearchDocument searchDocument) { AddSearchDocumentInternal(searchDocument, false); }