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

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

            FulltextBackgroundTaskExecutor = new TaskExecutor();
        }
Esempio n. 2
0
        /// <summary>
        ///     Sets index as default if it's the first one.
        /// </summary>
        /// <param name="name">
        ///     Index name translated into name of the folder under FT catalog directory
        /// </param>
        /// <param name="analyzer">
        /// </param>
        /// <param name="dropExisting">
        ///     Whether to drop existing index if exists
        /// </param>
        /// <returns>
        ///     The new index
        /// </returns>
        public IndexInformation AddOrOpenIndex(string name, Analyzer analyzer, bool dropExisting = false)
        {
            Check.DoCheckArgument(MultiIndex.GetIndex(name) == null, () => "Index already open");

            Check.DoRequireArgumentNotBlank(name, nameof(name));
            Check.DoRequireArgumentNotNull(analyzer, nameof(analyzer));

            var result = new IndexInformation(name);

            var indexDirectoryPath = GetIndexRootFolder(name);
            var dirInfo            = new DirectoryInfo(indexDirectoryPath);

            result.IsNew = !dirInfo.Exists;

            if (!result.IsNew)
            {
                dirInfo.Create();
            }
            else if (dropExisting)
            {
                dirInfo.Delete(true);
            }

            var luceneDir = LuceneIndex.PreparePersistentDirectory(indexDirectoryPath);

            var newIndex = new LuceneIndex(indexDirectoryPath, analyzer, luceneDir, EntityAdapter.DocumentKeyName);

            MultiIndex.AddIndex(name, newIndex);

            if (MultiIndex.IndexCount == 1)
            {
                SetDefaultIndex(name);
            }

            return(result);
        }
Esempio n. 3
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. 4
0
        public IndexInformation AddOrOpenSnowballIndex(string snowballStemmerName)
        {
            var analyzer = LuceneIndex.CreateSnowballAnalyzer(snowballStemmerName);

            return(AddOrOpenIndex(snowballStemmerName, analyzer, false));
        }