public async Task RemoveIndex(Guid songPk, CancellationToken cancellationToken)
 {
     await Task.Run(() =>
     {
         LucenePool.DeleteIndex(musicConfiguration.IndexPath, new Term(nameof(SongDocument.SongPk), songPk.ToString()));
     }, cancellationToken);
 }
 public async Task UpdateIndex(Song song, CancellationToken cancellationToken)
 {
     await Task.Run(() =>
     {
         LucenePool.UpdateIndex(musicConfiguration.IndexPath, new Term(nameof(SongDocument.SongPk), song.Pk.ToString()), song.GetSongDocument().GetDocument());
     }, cancellationToken);
 }
 public async Task AddIndex(Song song, CancellationToken cancellationToken)
 {
     await Task.Run(() =>
     {
         LucenePool.BuildIndex(musicConfiguration.IndexPath, true, true, new[] { song.GetSongDocument().GetDocument() }, true);
     }, cancellationToken);
 }
        public async Task InitIndex(CancellationToken cancellationToken)
        {
            logger.LogInformation("Init index start");
            var songDocuments = new List <SongDocument>();

            using (var scope = serviceScopeFactory.CreateScope())
            {
                var musicDbContext = scope.ServiceProvider.GetService <MusicDbContext>();

                var songs = musicDbContext.Songs.Include(u => u.SingerSongs).ThenInclude(u => u.Singer).Include(u => u.Album).Include(u => u.GenreSongs).ThenInclude(u => u.Genre);

                foreach (var item in songs)
                {
                    songDocuments.Add(item.GetSongDocument());
                }
            }

            logger.LogInformation("Init index for {0} documents", songDocuments.Count);

            await Task.Run(() =>
            {
                System.IO.Directory.CreateDirectory(musicConfiguration.IndexPath);
                LucenePool.BuildIndex(musicConfiguration.IndexPath, true, true, songDocuments.Select(u => u.GetDocument()), true);
                LucenePool.SaveResults(musicConfiguration.IndexPath, false);
            }, cancellationToken);

            logger.LogInformation("Init index finished");
        }
        public async Task SaveResults(CancellationToken cancellationToken)
        {
            logger.LogInformation("SaveResults start");
            await Task.Run(() =>
            {
                LucenePool.SaveResults(musicConfiguration.IndexPath, true);
            }, cancellationToken);

            logger.LogInformation("SaveResults successful");
        }
        public async Task DeleteAllIndex(CancellationToken cancellationToken)
        {
            logger.LogInformation("DeleteAllIndex start");

            await Task.Run(() =>
            {
                LucenePool.DeleteAllIndex(musicConfiguration.IndexPath);
            }, cancellationToken);

            logger.LogInformation("DeleteAllIndex successful");
        }
 public void Dispose()
 {
     LucenePool.SaveResultsAndClearLucenePool(musicConfiguration.IndexPath);
     logger.LogInformation("Dispose successful");
 }