Skip to content

Commit

Permalink
Merge pull request #19 from episerver/bugfix/CMS-23557-indexing-job-n…
Browse files Browse the repository at this point in the history
…umber-of-contents-indexed-is-always-displayed-3

Fix index job history, fix logger
  • Loading branch information
hungoptimizely authored May 19, 2022
2 parents df719a3 + 9f4c1f7 commit ec860ab
Show file tree
Hide file tree
Showing 20 changed files with 118 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public override void IndexPublishedContent()

if (success)
{
result.IndexingCount += 1;
result.IndexingCount += contentRequestToIndex.Count();
}
else
{
result.NumberOfContentErrors += 1;
result.NumberOfContentErrors += contentRequestToIndex.Count();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,27 @@ public class IndexingController : ControllerBase
private readonly IIndexingServiceHandler _indexingServiceHandler;
private readonly IIndexingServiceSettings _indexingServiceSettings;
private readonly IResponseExceptionHelper _responseExceptionHelper;
private readonly ILogger<IndexingController> _logger;

public IndexingController(ISecurityHandler securityHandler,
IIndexingServiceHandler indexingServiceHandler,
IIndexingServiceSettings indexingServiceSettings,
IResponseExceptionHelper responseExceptionHelper)
IResponseExceptionHelper responseExceptionHelper,
ILogger<IndexingController> logger)
{
_securityHandler = securityHandler;
_indexingServiceHandler = indexingServiceHandler;
_indexingServiceSettings = indexingServiceSettings;
_responseExceptionHelper = responseExceptionHelper;
_logger = logger;
}

//POST: reset?namedIndex={namedIndex}&accessKey={accessKey}
[HttpPost]
[Route("reset")]
public IActionResult ResetIndex(string namedIndex, string accessKey)
{
IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Reset of index: {0} requested", namedIndex));
_logger.LogDebug(string.Format("Reset of index: {0} requested", namedIndex));

if (!_securityHandler.IsAuthenticated(accessKey, AccessLevel.Modify))
{
Expand Down
20 changes: 11 additions & 9 deletions src/EPiServer.Search.IndexingService/Helpers/DocumentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ namespace EPiServer.Search.IndexingService.Helpers
public class DocumentHelper : IDocumentHelper
{
private readonly IResponseExceptionHelper _responseExceptionHelper;
public DocumentHelper(IResponseExceptionHelper responseExceptionHelper)
private readonly ILogger<DocumentHelper> _logger;
public DocumentHelper(IResponseExceptionHelper responseExceptionHelper, ILogger<DocumentHelper> logger)
{
_responseExceptionHelper = responseExceptionHelper;
_logger = logger;
}
public Collection<ScoreDocument> SingleIndexSearch(string q, NamedIndex namedIndex, int maxHits, out int totalHits)
{
Expand All @@ -29,7 +31,7 @@ public Collection<ScoreDocument> SingleIndexSearch(string q, NamedIndex namedInd

try
{
IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Creating Lucene QueryParser for index '{0}' with expression '{1}' with analyzer '{2}'", namedIndex.Name, q, IndexingServiceSettings.Analyzer.ToString()));
_logger.LogDebug(string.Format("Creating Lucene QueryParser for index '{0}' with expression '{1}' with analyzer '{2}'", namedIndex.Name, q, IndexingServiceSettings.Analyzer.ToString()));
QueryParser parser = new PerFieldQueryParserWrapper(IndexingServiceSettings.LuceneVersion, IndexingServiceSettings.DefaultFieldName, IndexingServiceSettings.Analyzer, IndexingServiceSettings.LowercaseFields);
var baseQuery = parser.Parse(q);
using (IndexReader reader = DirectoryReader.Open(namedIndex.Directory))
Expand Down Expand Up @@ -64,7 +66,7 @@ public void OptimizeIndex(NamedIndex namedIndex)

try
{
IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start optimizing index"));
_logger.LogDebug(string.Format("Start optimizing index"));

var iwc = new IndexWriterConfig(IndexingServiceSettings.LuceneVersion, IndexingServiceSettings.Analyzer)
{
Expand All @@ -75,12 +77,12 @@ public void OptimizeIndex(NamedIndex namedIndex)
iWriter.ForceMerge(1);
}

IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End optimizing index"));
_logger.LogDebug(string.Format("End optimizing index"));

}
catch (Exception e)
{
IndexingServiceSettings.IndexingServiceServiceLog.LogError(string.Format("Failed to optimize index: '{0}'. Message: {1}{2}{3}", namedIndex.Name, e.Message, Environment.NewLine, e.StackTrace));
_logger.LogError(string.Format("Failed to optimize index: '{0}'. Message: {1}{2}{3}", namedIndex.Name, e.Message, Environment.NewLine, e.StackTrace));
}
finally
{
Expand All @@ -90,7 +92,7 @@ public void OptimizeIndex(NamedIndex namedIndex)
//Fire event
IndexingController.OnIndexedOptimized(this, new OptimizedEventArgs(namedIndex.Name));

IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Optimized index: '{0}'", namedIndex.Name));
_logger.LogDebug(string.Format("Optimized index: '{0}'", namedIndex.Name));
}
public Collection<ScoreDocument> MultiIndexSearch(string q, Collection<NamedIndex> namedIndexes, int maxHits, out int totalHits)
{
Expand All @@ -109,7 +111,7 @@ public Collection<ScoreDocument> MultiIndexSearch(string q, Collection<NamedInde

try
{
IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Creating Lucene QueryParser for index '{0}' with expression '{1}' with analyzer '{2}'", namedIndex.Name, q, IndexingServiceSettings.Analyzer.ToString()));
_logger.LogDebug(string.Format("Creating Lucene QueryParser for index '{0}' with expression '{1}' with analyzer '{2}'", namedIndex.Name, q, IndexingServiceSettings.Analyzer.ToString()));
readers[i] = DirectoryReader.Open(namedIndex.Directory);
}
catch (Exception e)
Expand Down Expand Up @@ -315,14 +317,14 @@ public Lucene.Net.Store.Directory CreateIndex(string name, System.IO.DirectoryIn
}
catch (Exception e)
{
IndexingServiceSettings.IndexingServiceServiceLog.LogError(string.Format("Failed to create index for path: '{0}'. Message: {1}{2}'", directoryInfo.FullName, e.Message, e.StackTrace));
_logger.LogError(string.Format("Failed to create index for path: '{0}'. Message: {1}{2}'", directoryInfo.FullName, e.Message, e.StackTrace));
}
finally
{
IndexingServiceSettings.ReaderWriterLocks[name].ExitWriteLock();
}

IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Created index for path: '{0}'", directoryInfo.FullName));
_logger.LogDebug(string.Format("Created index for path: '{0}'", directoryInfo.FullName));

return dir;
}
Expand Down
Loading

0 comments on commit ec860ab

Please sign in to comment.