当前位置: 首页>>代码示例>>C#>>正文


C# IndexWriter.DeleteDocuments方法代码示例

本文整理汇总了C#中Lucene.Net.Index.IndexWriter.DeleteDocuments方法的典型用法代码示例。如果您正苦于以下问题:C# IndexWriter.DeleteDocuments方法的具体用法?C# IndexWriter.DeleteDocuments怎么用?C# IndexWriter.DeleteDocuments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Index.IndexWriter的用法示例。


在下文中一共展示了IndexWriter.DeleteDocuments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildIndex

        //END
        //this method creates document from an ObjectToIndex
        public void BuildIndex(FileToIndex file)
        {
            using (var analyzer = new Lucene.Net.Analysis.Ru.RussianAnalyzer(Version.LUCENE_30))
            {
                using (IndexWriter idxw = new IndexWriter(_directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    //check if document exists, if true deletes existing

                    var searchQuery = new TermQuery(new Term("Id", file.Id.ToString()));
                    idxw.DeleteDocuments(searchQuery);
                    //creation
                    Document doc = new Document();
                    doc.Add(new Field("Id", file.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));//аналайзер разбивает строки на слова
                    doc.Add(new Field("Title", file.Title, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Description", file.Description, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Authors", file.Authors, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Text", file.Text, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Hashtags", file.Hashtags, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Discipline", file.Discipline, Field.Store.YES, Field.Index.ANALYZED));
                    //write the document to the index
                    idxw.AddDocument(doc);
                    //optimize and close the writer
                    idxw.Commit();

                    idxw.Optimize();

                }
            }
        }
开发者ID:LebGrigori,项目名称:StudentWorksSearch,代码行数:31,代码来源:LuceneEngine.cs

示例2: Test_IndexReader_IsCurrent

        public void Test_IndexReader_IsCurrent()
        {
            RAMDirectory ramDir = new RAMDirectory();
            IndexWriter writer = new IndexWriter(ramDir, new KeywordAnalyzer(), true, new IndexWriter.MaxFieldLength(1000));
            Field field = new Field("TEST", "mytest", Field.Store.YES, Field.Index.ANALYZED);
            Document doc = new Document();
            doc.Add(field);
            writer.AddDocument(doc);

            IndexReader reader = writer.GetReader();

            writer.DeleteDocuments(new Lucene.Net.Index.Term("TEST", "mytest"));

            Assert.IsFalse(reader.IsCurrent());

            int resCount1 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")),100).TotalHits;
            Assert.AreEqual(1, resCount1);

            writer.Commit();

            Assert.IsFalse(reader.IsCurrent());

            int resCount2 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")),100).TotalHits;
            Assert.AreEqual(1, resCount2, "Reopen not invoked yet, resultCount must still be 1.");

            reader = reader.Reopen();
            Assert.IsTrue(reader.IsCurrent());

            int resCount3 = new IndexSearcher(reader).Search(new TermQuery(new Term("TEST", "mytest")), 100).TotalHits;
            Assert.AreEqual(0, resCount3, "After reopen, resultCount must be 0.");

            reader.Close();
            writer.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:34,代码来源:TestOldPatches.cs

示例3: TestBackToTheFuture

        public virtual void TestBackToTheFuture()
        {
            Directory dir = NewDirectory();
            IndexWriter iw = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, null));

            Document doc = new Document();
            doc.Add(NewStringField("foo", "bar", Field.Store.NO));
            iw.AddDocument(doc);

            doc = new Document();
            doc.Add(NewStringField("foo", "baz", Field.Store.NO));
            iw.AddDocument(doc);

            DirectoryReader r1 = DirectoryReader.Open(iw, true);

            iw.DeleteDocuments(new Term("foo", "baz"));
            DirectoryReader r2 = DirectoryReader.Open(iw, true);

            FieldCache.DEFAULT.GetDocTermOrds(GetOnlySegmentReader(r2), "foo");

            SortedSetDocValues v = FieldCache.DEFAULT.GetDocTermOrds(GetOnlySegmentReader(r1), "foo");
            Assert.AreEqual(2, v.ValueCount);
            v.Document = 1;
            Assert.AreEqual(1, v.NextOrd());

            iw.Dispose();
            r1.Dispose();
            r2.Dispose();
            dir.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:30,代码来源:TestDocTermOrds.cs

示例4: AddItemToIndex

        private void AddItemToIndex(AbstactDocument doc, IndexWriter writer)
        {
            var query = new BooleanQuery();
            query.Add(new TermQuery(new Term("Id", doc.Id.ToString())), Occur.MUST);
            query.Add(new TermQuery(new Term("Type", doc.Type)), Occur.MUST);

            writer.DeleteDocuments(query);
            writer.AddDocument(doc.Document);
        }
开发者ID:ASbeletsky,项目名称:Cinema3D,代码行数:9,代码来源:BaseWriter.cs

示例5: TestSplit

        public void TestSplit()
        {
            string format = "{0:000000000}";
            IndexWriter w;
            using (Directory dir = NewDirectory())
            {
                using (w = new IndexWriter(dir, NewIndexWriterConfig(
                    TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false))
                    .SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE).SetMergePolicy(NoMergePolicy.COMPOUND_FILES)))
                {
                    for (int x = 0; x < 11; x++)
                    {
                        Document doc = CreateDocument(x, "1", 3, format);
                        w.AddDocument(doc);
                        if (x % 3 == 0) w.Commit();
                    }
                    for (int x = 11; x < 20; x++)
                    {
                        Document doc = CreateDocument(x, "2", 3, format);
                        w.AddDocument(doc);
                        if (x % 3 == 0) w.Commit();
                    }
                }

                Term midTerm = new Term("id", string.Format(CultureInfo.InvariantCulture, format, 11));


                CheckSplitting(dir, midTerm, 11, 9);

                // delete some documents
                using (w = new IndexWriter(dir, NewIndexWriterConfig(

                    TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false))
                        .SetOpenMode(IndexWriterConfig.OpenMode_e.APPEND).SetMergePolicy(NoMergePolicy.COMPOUND_FILES)))
                {
                    w.DeleteDocuments(midTerm);
                    w.DeleteDocuments(new Term("id", string.Format(CultureInfo.InvariantCulture, format, 2)));
                }


                CheckSplitting(dir, midTerm, 10, 8);

            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:44,代码来源:TestPKIndexSplitter.cs

示例6: ClearIndexRecord

 public static void ClearIndexRecord(int id)
 {
     var analyzer = new StandardAnalyzer(Version.LUCENE_29);
     using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
     {
         var searchQuery = new TermQuery(new Term("Id", Convert.ToString(id)));
         writer.DeleteDocuments(searchQuery);
         analyzer.Close();
     }
 }
开发者ID:Lumenela,项目名称:WebPresentations,代码行数:10,代码来源:LuceneIndexer.cs

示例7: DeleteIndex

 public void DeleteIndex(int id)
 {
     var analyzer = new StandardAnalyzer(Version.LUCENE_30);
     using (var writer = new IndexWriter(Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
     {
         var searchQuery = new TermQuery(new Term(SearchingFields.Id.ToString(), id.ToString()));
         writer.DeleteDocuments(searchQuery);
         analyzer.Close();
     }
 }
开发者ID:MikhailGogolushko,项目名称:lmsystem,代码行数:10,代码来源:BaseSearchMethod.cs

示例8: DeleteFromIndex

        public void DeleteFromIndex(Term term)
        {
            Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo(serverPath));
            Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
            IndexWriter writer = new IndexWriter(directory, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED);

            writer.DeleteDocuments(term);
            writer.Commit();
            writer.Close();
        }
开发者ID:supermuk,项目名称:iudico,代码行数:10,代码来源:SearchPlugin.cs

示例9: FindChangedAndIndex

        public int FindChangedAndIndex()
        {
            var lastDateTimeFile = Path.Combine(path, "last.time");
            var lastDateTime = DateTime.MinValue;
            try
            {
                if (File.Exists(lastDateTimeFile))
                {
                    lastDateTime = DateTime.Parse(File.ReadAllText(lastDateTimeFile)).ToUniversalTime();
                }
            }
            catch (FormatException) { }
            catch (ArgumentNullException) { }

            var copyLastDateTime = lastDateTime;
            lastDateTime = DateTime.UtcNow;

            var texts = SelectTextsForIndex(copyLastDateTime, true);

            if (0 < texts.Count)
            {
                var directory = GetOrCreateDirectory(path);
                var analyzer = new AnalyzersProvider().GetAnalyzer(tenant.GetCulture().TwoLetterISOLanguageName);
                var create = directory.ListAll().Length == 0;
                var index = new IndexWriter(directory, analyzer, create, IndexWriter.MaxFieldLength.UNLIMITED);
                try
                {
                    foreach (var t in texts)
                    {
                        var term = new Term("Id", t.Item1);
                        if (string.IsNullOrEmpty(t.Item2))
                        {
                            index.DeleteDocuments(term);
                        }
                        else
                        {
                            var doc = new Document();
                            doc.Add(new Field("Id", t.Item1, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.YES));
                            doc.Add(new Field("Text", t.Item2, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
                            index.UpdateDocument(term, doc);
                        }
                    }
                }
                finally
                {
                    index.Optimize();
                    index.Commit();
                    index.Close();
                }

                File.WriteAllText(lastDateTimeFile, lastDateTime.ToString("o"));
            }

            return texts.Count;
        }
开发者ID:Inzaghi2012,项目名称:teamlab.v7.5,代码行数:55,代码来源:TextIndexer.cs

示例10: ClearLuceneIndexRecord

 public static void ClearLuceneIndexRecord(int record_id)
 {
     // init lucene
     using (var analyzer = new RussianAnalyzer(Version.LUCENE_30))
     using (var writer = new IndexWriter(LuceneConfig.Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
     {
         // remove older index entry
         var searchQuery = new TermQuery(new Term("Id", record_id.ToString()));
         writer.DeleteDocuments(searchQuery);
     }
 }
开发者ID:antgerasim,项目名称:ArmProtoClean,代码行数:11,代码来源:LuceneIndex.cs

示例11: RemoveIndex

        public void RemoveIndex(Guid id)
        {
            var directory = FSDirectory.Open(_path);

            using (
                var write = new IndexWriter(directory, _analyzer, !IndexReader.IndexExists(directory),
                                            IndexWriter.MaxFieldLength.UNLIMITED))
            {
                write.DeleteDocuments(new Term("id", id.ToString()));
            }
        }
开发者ID:peisheng,项目名称:EASYFRAMEWORK,代码行数:11,代码来源:TheIndexService.cs

示例12: ClearLuceneIndexRecord

        /// <summary>
        /// 按id清楚
        /// </summary>
        /// <param name="recordId"></param>
        public static void ClearLuceneIndexRecord(int recordId)
        {
            //var analyzer = new StandardAnalyzer(Version.LUCENE_30);
            var analyzer = SearcherBase.GetAnalyzer();
            using (var writer = new IndexWriter(SearcherBase.Directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
            {
                var searchQuery = new TermQuery(new Term("Id", recordId.ToString()));
                writer.DeleteDocuments(searchQuery);

                analyzer.Close();
            }
        }
开发者ID:applenele,项目名称:SmallCode,代码行数:16,代码来源:BlogSearcher.cs

示例13: DeleteManualFromIndex

 /// <summary>
 /// Deletes the manual from index '
 /// </summary>
 /// <param name="manualId">The manual identifier.</param>
 public void DeleteManualFromIndex(int manualId)
 {
     var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
     using (var writer = new IndexWriter(directoryTemp, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
     {
         var query = new TermQuery(new Term("Id", manualId.ToString()));
         writer.DeleteDocuments(query);
         analyzer.Close();
         writer.Optimize();
         writer.Dispose();
     }
 }
开发者ID:felldek,项目名称:test,代码行数:16,代码来源:SearchService.cs

示例14: AddToIndex

        private void AddToIndex(Project project, IndexWriter writer)
        {
            var searchQuery = new TermQuery(new Term(SearchingFields.Id.ToString(), project.Id.ToString()));
            writer.DeleteDocuments(searchQuery);

            var doc = new Document();

            doc.Add(new Field(SearchingFields.Id.ToString(), project.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(SearchingFields.Name.ToString(), project.Title, Field.Store.YES, Field.Index.ANALYZED));

            writer.AddDocument(doc);
        }
开发者ID:MikhailGogolushko,项目名称:lmsystem,代码行数:12,代码来源:ProjectSearchMethod.cs

示例15: _addToLuceneIndex

        private static void _addToLuceneIndex(SampleData sampleData, IndexWriter writer)
        {
            var searchQuery = new TermQuery(new Term("Id", sampleData.Id.ToString()));
            writer.DeleteDocuments(searchQuery);

            var doc = new Document();

            doc.Add(new Field("Id", sampleData.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Name", sampleData.Name, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Description", sampleData.Description, Field.Store.YES, Field.Index.ANALYZED));

            writer.AddDocument(doc);
        }
开发者ID:cgideon,项目名称:CSharpSandbox,代码行数:13,代码来源:LuceneSearch.cs


注:本文中的Lucene.Net.Index.IndexWriter.DeleteDocuments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。