Beispiel #1
0
        public DocumentStorageWithFulltextSearch(IDocumentStorage <TDoc, TKey> storage, IStandaloneFulltextSearchEngine <TDoc, THeader, TKey> searchEngine)
        {
            Storage      = storage;
            SearchEngine = searchEngine;

            SupportedStemmerNames = LuceneIndex.GetAvailableSnowballStemmers().ToList();

            FulltextBackgroundTaskExecutor = new TaskExecutor();
        }
Beispiel #2
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);
            }
        }