Exemplo n.º 1
0
        protected virtual Directory CreateIndex()
        {
            var index = new RAMDirectory();

            var indexWriterAnalyzer = CreateAnalyzer();
            var config = IndexUtils.CreateWriterConfig(indexWriterAnalyzer);

            using (var writer = new IndexWriter(index, config))
            {
                void indexDocumentGroup(IEnumerable <Document> documents)
                {
                    foreach (var doc in documents)
                    {
                        writer.AddDocument(doc);
                    }

                    Interlocked.Increment(ref GroupsAddedToIndex);
                    IndexingProgress?.Invoke();
                }

                IndexUtils.ForEach(GetDocumentGroupsToIndex(), indexDocumentGroup);

                writer.Flush(triggerMerge: true, applyAllDeletes: false);
                writer.Commit();
            }

            return(index);
        }
Exemplo n.º 2
0
        public void BeginIndex(Directory index)
        {
            var config = IndexUtils.CreateWriterConfig(new SpellcheckerAnalyzer());

            _index       = index;
            _indexWriter = new IndexWriter(_index, config);
        }
Exemplo n.º 3
0
        public Directory CreateIndex()
        {
            if (IsLoading || IsLoaded)
            {
                throw new InvalidOperationException();
            }

            IsLoading = true;

            var index = new RAMDirectory();

            var indexWriterAnalyzer = Adapter.CreateAnalyzer();
            var config = IndexUtils.CreateWriterConfig(indexWriterAnalyzer);

            using (var writer = new IndexWriter(index, config))
            {
                void indexDocumentGroup(IEnumerable <Document> documents)
                {
                    if (_aborted)
                    {
                        return;
                    }

                    foreach (var doc in documents)
                    {
                        if (_aborted)
                        {
                            return;
                        }

                        writer.AddDocument(doc);
                    }

                    Interlocked.Increment(ref GroupsAddedToIndex);
                    IndexingProgress?.Invoke();
                }

                IndexUtils.ForEach(GetDocumentGroupsToIndex(), indexDocumentGroup);

                if (_aborted)
                {
                    return(null);
                }

                writer.Flush(triggerMerge: true, applyAllDeletes: false);
                writer.Commit();
            }

            IsLoading = false;

            return(index);
        }