Esempio n. 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;
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 5
0
 public void SetDefaultIndex(string stemmerName)
 {
     SearchEngine.SetDefaultIndex(stemmerName);
 }
Esempio n. 6
0
 public void RemoveIndex(string stemmerName)
 {
     SearchEngine.RemoveIndex(stemmerName);
 }
Esempio n. 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));
 }
Esempio n. 8
0
 /// <inheritdoc />
 public IList <THeader> GetTopInPeriod(DateTime?periodStart, DateTime?periodEnd, int maxResults, SearchableDocumentTime searchableDocumentTime = SearchableDocumentTime.LastUpdate)
 {
     return(SearchEngine.GetTopInPeriod(periodStart, periodEnd, maxResults, searchableDocumentTime));
 }
Esempio n. 9
0
 public IList <THeader> Search(string queryText, int maxResults)
 {
     return(SearchEngine.Search(queryText, maxResults));
 }