Exemple #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    // dispose managed state (managed objects).
                    FulltextBackgroundTaskExecutor.WaitForAllCurrentTasksToFinish(5000);
                    FulltextBackgroundTaskExecutor.Dispose();

                    Storage?.Dispose();
                    SearchEngine?.Dispose();
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                // set large fields to null.

                _disposedValue = true;
            }
        }
Exemple #2
0
        public static NoteStorage CreateStandard(LiteDatabase database, string rootDirectoryPath, bool updateLastUpdateAutomatically = false)
        {
            Check.DoRequireArgumentNotNull(database, nameof(database));
            Check.DoRequireArgumentNotNull(rootDirectoryPath, nameof(rootDirectoryPath));

            var fulltextPath = Path.Combine(rootDirectoryPath, "ft");

            Directory.CreateDirectory(fulltextPath);


            var luceneAdapter = new LuceneNoteAdapter();
            var storage       = new LiteDbStorage <Note>(database, new NoteAdapter(updateLastUpdateAutomatically));
            var multiIndex    = new MultiIndex(luceneAdapter.DocumentKeyName);
            var searchEngine  = new SearchEngine <Note, INoteHeader, string>(fulltextPath, luceneAdapter, multiIndex);

            var result = new NoteStorage(storage, searchEngine)
            {
                RootPath = rootDirectoryPath
            };

            return(result);
        }
Exemple #3
0
        public TDoc Delete(TKey id)
        {
            var result = Storage.Delete(id);

            FulltextBackgroundTaskExecutor.Schedule(() =>
            {
                if (EntityAdapter.CanConvertStorageKey)
                {
                    SearchEngine.Delete(EntityAdapter.GetFulltextFromStorageKey(id));
                }
                else if (result != null)
                {
                    SearchEngine.Delete(EntityAdapter.GetFulltextKey(result));
                }

                if (EntityAdapter.CanConvertStorageKey || result != null)
                {
                    SearchEngine.CommitFulltextIndex();
                }
            });

            return(result);
        }
Exemple #4
0
        public void OpenOrCreateIndexes(IEnumerable <string> stemmerNames, Action <double> progressReporter = null)
        {
            Check.DoRequireArgumentNotNull(stemmerNames, nameof(stemmerNames));

            var languageNames = stemmerNames.ToCaseInsensitiveSet();

            var allSupportedLangs = LuceneIndex.GetAvailableSnowballStemmers().ToCaseInsensitiveSet();

            var unknownLangs = string.Join(",", languageNames.Where(n => !allSupportedLangs.Contains(n)));

            if (!string.IsNullOrEmpty(unknownLangs))
            {
                throw new FulltextException($"The following configured languages are not supported: {unknownLangs}");
            }

            var newIndexes = new List <IndexInformation>();

            foreach (var stemmerName in stemmerNames)
            {
                var info = SearchEngine.AddOrOpenSnowballIndex(stemmerName);
                if (info.IsNew)
                {
                    newIndexes.Add(info);
                }
            }

            if (languageNames.Count > 1)
            {
                SearchEngine.SetDefaultIndex(stemmerNames.First());
            }

            if (newIndexes.Count > 0)
            {
                RebuildIndexes(newIndexes.Select(x => x.Name).ToArray(), progressReporter);
            }
        }
Exemple #5
0
 public void SetDefaultIndex(string stemmerName)
 {
     SearchEngine.SetDefaultIndex(stemmerName);
 }
Exemple #6
0
 public void RemoveIndex(string stemmerName)
 {
     SearchEngine.RemoveIndex(stemmerName);
 }
Exemple #7
0
 /// <inheritdoc />
 public IList <THeader> SearchInPeriod(DateTime?periodStart, DateTime?periodEnd, string queryText, int maxResults,
                                       SearchableDocumentTime searchableDocumentTime = SearchableDocumentTime.LastUpdate)
 {
     return(SearchEngine.SearchInPeriod(periodStart, periodEnd, queryText, maxResults, searchableDocumentTime));
 }
Exemple #8
0
 /// <inheritdoc />
 public IList <THeader> GetTopInPeriod(DateTime?periodStart, DateTime?periodEnd, int maxResults, SearchableDocumentTime searchableDocumentTime = SearchableDocumentTime.LastUpdate)
 {
     return(SearchEngine.GetTopInPeriod(periodStart, periodEnd, maxResults, searchableDocumentTime));
 }
Exemple #9
0
 public IList <THeader> Search(string queryText, int maxResults)
 {
     return(SearchEngine.Search(queryText, maxResults));
 }