Skip to content

Commit

Permalink
Merge pull request #15 from episerver/bugfix/CMS-21661-Lack-of-result…
Browse files Browse the repository at this point in the history
…-lists-of-Files

Fix indexing media data
  • Loading branch information
hungoptimizely authored May 9, 2022
2 parents ddfbf8e + bef6d34 commit 032bde3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/EPiServer.Search.IndexingService/Helpers/DocumentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Collection<ScoreDocument> SingleIndexSearch(string q, NamedIndex namedInd
{
var scoreDocuments = new Collection<ScoreDocument>();
totalHits = 0;
var rwl = new ReaderWriterLockSlim();
var rwl = IndexingServiceSettings.ReaderWriterLocks[namedIndex.Name];
rwl.EnterReadLock();

try
Expand Down Expand Up @@ -58,7 +58,7 @@ public Collection<ScoreDocument> SingleIndexSearch(string q, NamedIndex namedInd
}
public void OptimizeIndex(NamedIndex namedIndex)
{
var rwl = new ReaderWriterLockSlim();
var rwl = IndexingServiceSettings.ReaderWriterLocks[namedIndex.Name];

rwl.EnterWriteLock();

Expand Down Expand Up @@ -103,7 +103,7 @@ public Collection<ScoreDocument> MultiIndexSearch(string q, Collection<NamedInde
var i = 0;
foreach (var namedIndex in namedIndexes)
{
var rwl = new ReaderWriterLockSlim();
var rwl = IndexingServiceSettings.ReaderWriterLocks[namedIndex.Name];
locks.Add(rwl);
rwl.EnterReadLock();

Expand Down Expand Up @@ -298,8 +298,7 @@ public Lucene.Net.Store.Directory CreateIndex(string name, System.IO.DirectoryIn
{
Lucene.Net.Store.Directory dir = null;

var rwl = new ReaderWriterLockSlim();
rwl.EnterWriteLock();
IndexingServiceSettings.ReaderWriterLocks[name].EnterWriteLock();

try
{
Expand All @@ -320,7 +319,7 @@ public Lucene.Net.Store.Directory CreateIndex(string name, System.IO.DirectoryIn
}
finally
{
rwl.ExitWriteLock();
IndexingServiceSettings.ReaderWriterLocks[name].ExitWriteLock();
}

IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Created index for path: '{0}'", directoryInfo.FullName));
Expand Down
6 changes: 3 additions & 3 deletions src/EPiServer.Search.IndexingService/Helpers/LuceneHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public bool WriteToIndex(string itemId, Document doc, NamedIndex namedIndex)
isOk = false;
}

var rwl = new ReaderWriterLockSlim();
var rwl = IndexingServiceSettings.ReaderWriterLocks[namedIndex.Name];

rwl.EnterWriteLock();

Expand Down Expand Up @@ -403,7 +403,7 @@ public Collection<ScoreDocument> GetScoreDocuments(string q, bool excludeNotPubl

public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef)
{
var rwl = new ReaderWriterLockSlim();
var rwl = IndexingServiceSettings.ReaderWriterLocks[namedIndex.Name];
var isOk = true;
Term term = null;

Expand Down Expand Up @@ -453,7 +453,7 @@ public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef
{
IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start deleting reference documents for id '{0}'", itemId.ToString()));

var rwlRef = new ReaderWriterLockSlim();
var rwlRef = IndexingServiceSettings.ReaderWriterLocks[namedIndex.ReferenceName];
rwlRef.EnterWriteLock();

try
Expand Down
10 changes: 10 additions & 0 deletions src/EPiServer.Search.IndexingService/IndexingServiceSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using EPiServer.Search.IndexingService.Configuration;
using EPiServer.Search.IndexingService.Controllers;
using EPiServer.Search.IndexingService.Helpers;
Expand Down Expand Up @@ -194,6 +196,11 @@ public static Analyzer Analyzer
}
}

/// <summary>
/// Gets ReaderWriterLocks for named indexes
/// </summary>
public static ConcurrentDictionary<string, ReaderWriterLockSlim> ReaderWriterLocks { get; } = new ConcurrentDictionary<string, ReaderWriterLockSlim>();

/// <summary>
/// Gets named indexes config elements
/// </summary>
Expand Down Expand Up @@ -278,6 +285,9 @@ private void LoadIndexes()
var directoryMain = new System.IO.DirectoryInfo(System.IO.Path.Combine(GetDirectoryPath(e.DirectoryPath), "Main"));
var directoryRef = new System.IO.DirectoryInfo(System.IO.Path.Combine(GetDirectoryPath(e.DirectoryPath), "Ref"));

ReaderWriterLocks.TryAdd(e.Name, new ReaderWriterLockSlim());
ReaderWriterLocks.TryAdd(e.Name + RefIndexSuffix, new ReaderWriterLockSlim());

try
{
if (!directoryMain.Exists)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.ObjectModel;
using System.Threading;
using EPiServer.Search.IndexingService.Helpers;
using Microsoft.Extensions.Logging;
using Moq;
Expand All @@ -11,6 +12,8 @@ public class DocumentHelperTestBase
protected readonly Mock<IResponseExceptionHelper> _responseExceptionHelperMock;
public DocumentHelperTestBase()
{
IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex1", new ReaderWriterLockSlim());
IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex2", new ReaderWriterLockSlim());
_responseExceptionHelperMock = new Mock<IResponseExceptionHelper>();

var logMock = new Mock<ILogger>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using EPiServer.Search.IndexingService.Helpers;
using System;
using System.Threading;
using EPiServer.Search.IndexingService.Helpers;
using Moq;

namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper
Expand All @@ -11,6 +13,10 @@ public class LuceneHelperTestBase
protected readonly Mock<IDocumentHelper> _documentHelperMock;
public LuceneHelperTestBase()
{
IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex1", new ReaderWriterLockSlim());
IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex1" + IndexingServiceSettings.RefIndexSuffix, new ReaderWriterLockSlim());
IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex2", new ReaderWriterLockSlim());

_feedHelperMock = new Mock<IFeedHelper>();
_commonFuncMock = new Mock<ICommonFunc>();
_responseExceptionHelperMock = new Mock<IResponseExceptionHelper>();
Expand Down

0 comments on commit 032bde3

Please sign in to comment.