-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves deprecation of search indexes
Closes #3776 Please read the issue during review. This is what comes to mind, but if there are better ideas, I am open to them :)
- Loading branch information
Showing
7 changed files
with
120 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
DNN Platform/Library/Services/Search/IndexingProviderBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// | ||
#region Usings | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using DotNetNuke.Common; | ||
using DotNetNuke.Services.Scheduling; | ||
using DotNetNuke.Services.Search.Entities; | ||
using DotNetNuke.Services.Search.Internals; | ||
|
||
#endregion | ||
|
||
namespace DotNetNuke.Services.Search | ||
{ | ||
/// <summary>A base class for search indexers.</summary> | ||
public abstract class IndexingProviderBase | ||
{ | ||
/// <summary>This method must save search documents in batches to minimize memory usage instead of returning all documents at once.</summary> | ||
/// <param name="portalId">ID of the portal for which to index items.</param> | ||
/// <param name="startDateLocal">Minimum modification date of items that need to be indexed.</param> | ||
/// <param name="indexer">A delegate function to send the collection of documents to for saving/indexing.</param> | ||
/// <returns>The number of documents indexed</returns> | ||
public abstract int IndexSearchDocuments(int portalId, | ||
ScheduleHistoryItem schedule, DateTime startDateLocal, Action<IEnumerable<SearchDocument>> indexer); | ||
|
||
private const string TimePostfix = "UtcTime"; | ||
private const string DataPostfix = "Data"; | ||
|
||
/// <summary>Retrieves the date/time of the last item to be indexed</summary> | ||
/// <param name="portalId">The portal ID.</param> | ||
/// <param name="scheduleId">The schedule ID.</param> | ||
/// <param name="localTime">The local time passed to <see cref="IndexSearchDocuments" />.</param> | ||
/// <returns>Either <paramref name="localTime"/> or the stored index time, whichever is earlier</returns> | ||
protected DateTime GetLocalTimeOfLastIndexedItem(int portalId, int scheduleId, DateTime localTime) | ||
{ | ||
var lastTime = SearchHelper.Instance.GetIndexerCheckpointUtcTime( | ||
scheduleId, ScheduleItemSettingKey(portalId, TimePostfix)).ToLocalTime(); | ||
return lastTime < localTime ? lastTime : localTime; | ||
} | ||
|
||
/// <summary>Stores the date/time of the last item to be indexed.</summary> | ||
/// <param name="portalId">The portal ID.</param> | ||
/// <param name="scheduleId">The schedule ID.</param> | ||
/// <param name="localTime">The local time to store.</param> | ||
protected void SetLocalTimeOfLastIndexedItem(int portalId, int scheduleId, DateTime localTime) | ||
{ | ||
SearchHelper.Instance.SetIndexerCheckpointUtcTime( | ||
scheduleId, ScheduleItemSettingKey(portalId, TimePostfix), localTime.ToUniversalTime()); | ||
} | ||
|
||
/// <summary>Retrieves free format data to help the indexer to perform its job</summary> | ||
/// <param name="portalId">The portal ID.</param> | ||
/// <param name="scheduleId">The schedule ID.</param> | ||
/// <returns>The checkpoint data</returns> | ||
protected string GetLastCheckpointData(int portalId, int scheduleId) | ||
{ | ||
return SearchHelper.Instance.GetIndexerCheckpointData(scheduleId, ScheduleItemSettingKey(portalId, DataPostfix)); | ||
} | ||
|
||
/// <summary>Stores free format data to help the indexer to perform its job</summary> | ||
/// <param name="portalId">The portal ID.</param> | ||
/// <param name="scheduleId">The schedule ID.</param> | ||
/// <param name="data">The data to store.</param> | ||
protected void SetLastCheckpointData(int portalId, int scheduleId, string data) | ||
{ | ||
SearchHelper.Instance.SetIndexerCheckpointData(scheduleId, ScheduleItemSettingKey(portalId, DataPostfix), data); | ||
} | ||
|
||
[Obsolete("Deprecated in DNN 7.4.2 Use 'IndexSearchDocuments' instead for lower memory footprint during search.. Scheduled removal in v10.0.0.")] | ||
public virtual IEnumerable<SearchDocument> GetSearchDocuments(int portalId, DateTime startDateLocal) | ||
{ | ||
return Enumerable.Empty<SearchDocument>(); | ||
} | ||
|
||
[Obsolete("Legacy Search (ISearchable) -- Deprecated in DNN 7.1. Use 'IndexSearchDocuments' instead.. Scheduled removal in v10.0.0.")] | ||
public virtual SearchItemInfoCollection GetSearchIndexItems(int portalId) | ||
{ | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a unique name for the IndexingProvider implementation that can be used | ||
/// to save/retrieve scheduler item {key,name} setting pairs per portal and feature. | ||
/// </summary> | ||
/// <param name="portalId">The ID of the portal</param> | ||
/// <param name="propertyId">The name of the property</param> | ||
/// <remarks> | ||
/// Note that changing the class name in derived classes will cause this key to differ | ||
/// from the names stored in the database; therefore, don't change the derived class | ||
/// [full] names once these are deployed to market in an actual release version. | ||
/// <para>The format of the key is as follows: | ||
/// <ol> | ||
/// <li>"Search" literal</li> | ||
/// <li>Name of the indexer class</li> | ||
/// <li>Hash of the full class name of the indexer class (this and the previous will keep the key short and unique)</li> | ||
/// <li>Portal ID the setting is related to</li> | ||
/// <li>An additional property identifier set by the caller (this allows more items to be saved per indexer per portal)</li> | ||
/// </ol> | ||
/// </para> | ||
/// </remarks> | ||
/// <returns>The setting key</returns> | ||
private string ScheduleItemSettingKey(int portalId, string propertyId) | ||
{ | ||
Requires.NotNullOrEmpty("propertyId", propertyId); | ||
var t = GetType(); | ||
return string.Join("_", "Search", t.Name, t.FullName.GetHashCode().ToString("x8"), portalId.ToString(), propertyId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters