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


C# IndexWriter.DeleteAll方法代码示例

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


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

示例1: CreateIndexFromDirectory

        public void CreateIndexFromDirectory()
        {
            string DirecotryPath = outputDirectoryName == null
                ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
                : Path.GetDirectoryName(outputDirectoryName);
            var directory = FSDirectory.Open(DirecotryPath);
            Analyzer analyzer = new TermAnalyzer();
            IndexWriter writer =
                new IndexWriter(directory, analyzer, true,
                    IndexWriter.MaxFieldLength.UNLIMITED);
            var files = FileHelper.GetFilesFromRelativePath(inputDirectoryName);

            writer.DeleteAll();
            foreach (var fileInfo in files)
            {
                //var detailedPath = DirecotryPath + "\\" + fileInfo.Name;
                //var detailedDirectory = FSDirectory.Open(detailedPath);
                //IndexWriter detailedlWriter = new IndexWriter(detailedDirectory, analyzer, true,
                //    IndexWriter.MaxFieldLength.UNLIMITED);
                Document doc = new Document();
                Document detailedDocument = new Document();
                var path = fileInfo.Directory + "\\" + fileInfo.Name;
                var reader = new StreamReader(path);
                doc.Add(new Field("content", reader, Field.TermVector.WITH_POSITIONS));
                writer.AddDocument(doc);
                reader.Close();
                reader = new StreamReader(path);
                detailedDocument.Add(new Field(fileInfo.Name, reader, Field.TermVector.WITH_POSITIONS));
                //detailedlWriter.AddDocument(detailedDocument);
                //detailedlWriter.Optimize();
                //detailedlWriter.Commit();
            }
            writer.Optimize();
            writer.Commit();
        }
开发者ID:shather,项目名称:dotLuceneSmallAPI,代码行数:35,代码来源:LuceneSearchHelper.cs

示例2: Run

        public static void Run(string[] args)
        {
            IDictionary<string, string> arguments = CommandHelpers.GetArguments(args, 1);
            if (arguments == null)
            {
                PrintUsage();
                return;
            }

            Lucene.Net.Store.Directory directory = CommandHelpers.GetLuceneDirectory(arguments);
            if (directory == null)
            {
                PrintUsage();
                return;
            }

            if (IndexReader.IndexExists(directory))
            {
                using (IndexWriter writer = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    writer.DeleteAll();
                    writer.Commit(new Dictionary<string, string>());
                }
            }

            Console.WriteLine("All Done");
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:27,代码来源:ResetLucene.cs

示例3: ClearIndex

        public void ClearIndex()
        {
            if (System.IO.Directory.GetFiles(this.index.Directory.FullName).Any())
            {
                try
                {
                    var analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
                    using (var writer = new IndexWriter(this.index, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
                    {
                        // remove older index entries
                        writer.DeleteAll();

                        // close handles
                        analyzer.Close();
                        writer.Dispose();
                    }

                    ForceUnlockIndex();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
开发者ID:aureliopires,项目名称:gisa,代码行数:25,代码来源:MockUnidadeFisicaUpdater.cs

示例4: DeleteAllItemsFromIndex

 public void DeleteAllItemsFromIndex()
 {
     using (var writer = new IndexWriter(LuceneDirectory, new StandardAnalyzer(Version.LUCENE_30), IndexWriter.MaxFieldLength.UNLIMITED))
     {
         writer.DeleteAll();
     }
 }
开发者ID:ASbeletsky,项目名称:Cinema3D,代码行数:7,代码来源:BaseWriter.cs

示例5: Main

        static void Main(string[] args)
        {
            // Initialize Lucene
            Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo("LuceneIndex"));
            StandardAnalyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
            IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);

            // Open DB connection
            OpenConnections();

            // Insert documents into the index

            // Clear the index
            writer.DeleteAll();
            string sql = "SELECT a.ArticleId, a.Title, a.IntroText, a.Content, a.Published, a.DateCreated, " +
                "u.UserName, a.SectionId FROM Article AS a INNER JOIN aspnet_Users AS u ON " +
                "a.CreatedBy = u.UserId";

            SqlCommand cmd = new SqlCommand(sql, dbConn);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                // Extract the fields to be indexed
                int articleId = reader.GetInt32(reader.GetOrdinal("ArticleId"));
                string title = reader["Title"].ToString();
                string content = reader["IntroText"].ToString() + reader["Content"].ToString();
                string intro = content.Substring(0, content.Length > 100 ? 100 : content.Length);
                string author = reader["UserName"].ToString();
                int sectionId = reader.GetInt32(reader.GetOrdinal("SectionId"));
                bool published = reader.GetBoolean(reader.GetOrdinal("Published"));
                DateTime pubDate = reader.GetDateTime(reader.GetOrdinal("DateCreated"));
                string strPubDate = DateTools.DateToString(pubDate, DateTools.Resolution.DAY);

                Document doc = new Document();
                doc.Add(new Field("ArticleId", articleId.ToString(), Field.Store.YES, Field.Index.NO));
                doc.Add(new Field("Title", title, Field.Store.YES, Field.Index.ANALYZED));
                doc.Add(new Field("Content", content, Field.Store.NO, Field.Index.ANALYZED));
                doc.Add(new Field("Intro", title, Field.Store.YES, Field.Index.NO));
                doc.Add(new Field("Author", author, Field.Store.YES, Field.Index.NO));
                doc.Add(new Field("SectionId", sectionId.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("Published", published.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("PubDate", strPubDate, Field.Store.YES, Field.Index.NOT_ANALYZED));

                writer.AddDocument(doc);
            }

            // Close everything, shut down.
            writer.Optimize();
            writer.Commit();
            writer.Close();

            dbConn.Close();
        }
开发者ID:rnietoy,项目名称:nietoyosten,代码行数:54,代码来源:CreateLuceneIndex.cs

示例6: ClearIndex

        /// <summary>
        /// Clears the entire index.
        /// </summary>
        /// <param name="luceneVersion">The lucene version.</param>
        /// <param name="fsDirectory">The fs directory.</param>
        /// <param name="maxFieldLength">Maximum length of the field.</param>
		public virtual void ClearIndex(Version luceneVersion, FSDirectory fsDirectory, IndexWriter.MaxFieldLength maxFieldLength)
		{
			var analyzer = new StandardAnalyzer(luceneVersion);

			using (var indexWriter = new IndexWriter(fsDirectory, analyzer, maxFieldLength))
			{
				indexWriter.DeleteAll();

				analyzer.Close();
			}
		}
开发者ID:KaraokeStu,项目名称:LeadPipe.Net,代码行数:17,代码来源:SearchIndexClearer.cs

示例7: ClearIndex

        /// <summary>
        /// Clears the index.
        /// </summary>
        public void ClearIndex()
        {
            var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
            using (var writer = new IndexWriter(directoryTemp, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
            {
                writer.DeleteAll();

                analyzer.Close();
                writer.Optimize();
                writer.Dispose();
            }
        }
开发者ID:felldek,项目名称:test,代码行数:15,代码来源:SearchService.cs

示例8: IndexMaker

	public IndexMaker(string indexDir, string fieldName)
	{

        _indexDir = indexDir;
        _fieldName = fieldName;
		using (Directory directory = FSDirectory.Open(_indexDir))
		using (Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
		using (IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
		{
			writer.DeleteAll();
		}
    }
开发者ID:irfiit,项目名称:wikipedia,代码行数:12,代码来源:IndexMaker.cs

示例9: Build

        public static void Build(IndexWriter writer)
        {
            writer.DeleteAll();

            Populate(GetPrograms(), writer);
            Populate(GetApplications(), writer);
            Populate(GetInitiatives(), writer);
            Populate(GetInitiativeTasks(), writer);

            writer.Optimize();
            writer.Commit();
            writer.Dispose();
        }
开发者ID:szwork2013,项目名称:BoiPlt,代码行数:13,代码来源:IndexBuilder.cs

示例10: RebuildIndex

 private static void RebuildIndex(Lucene.Net.Store.Directory directory, Analyzer analyzer, List<Product> products)
 {
     IndexWriter writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.LIMITED);
     writer.DeleteAll();
     writer.Commit();
     foreach (Product p in products) // Add Documents to the Index.
     {
         AddDocumentToIndex(p, writer);
     }
     writer.Optimize();
     writer.Commit();
     writer.Dispose();
 }
开发者ID:avinashbhujan,项目名称:SalesTaxObserverPatternWithLucene,代码行数:13,代码来源:ProductIndexer.cs

示例11: Setup

        public void Setup()
        {
            var dirProvider = new Mock<IDataDirectoryProvider>();
            dirProvider.Setup(x => x.DataDirectoryPath).Returns(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\MyJobLeadsTestIndex");

            _provider = new LuceneSearchProvider(dirProvider.Object);

            // Load the index and delete all documents so it's fresh for the test
            _indexDirectory = Lucene.Net.Store.FSDirectory.Open(new DirectoryInfo(_provider.LuceneIndexBaseDirectory));
            bool createNewIndex = !IndexReader.IndexExists(_indexDirectory);
            var writer = new IndexWriter(_indexDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED);
            writer.DeleteAll();
            writer.Close();
        }
开发者ID:KallDrexx,项目名称:MyJobLeads,代码行数:14,代码来源:LuceneSearchProviderTests.cs

示例12: RunInternal

        protected override Task RunInternal(CancellationToken cancellationToken)
        {
            if (IndexReader.IndexExists(_directory))
            {
                using (var writer = new IndexWriter(_directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30), true, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    writer.DeleteAll();
                    writer.Commit(new Dictionary<string, string>());
                }
            }

            Logger.LogInformation("All Done");

            return Task.FromResult(false);
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:15,代码来源:ClearLuceneJob.cs

示例13: ClearIndex

 /// <summary>
 /// Clear all index
 /// </summary>
 /// <returns>true if sucsess, false if directory was locked</returns>
 public bool ClearIndex( )
 {
     try
     {
         var analyzer = new StandardAnalyzer(Version.LUCENE_30);
         using (var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
         {
             writer.DeleteAll();
             analyzer.Close();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
开发者ID:NonameProject,项目名称:Noname,代码行数:21,代码来源:MyBaseSearcher.cs

示例14: Index

 public void Index(List<invType> types)
 {
     using(  IndexWriter indexWriter = new IndexWriter(azureDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), true, new Lucene.Net.Index.IndexWriter.MaxFieldLength(IndexWriter.DEFAULT_MAX_FIELD_LENGTH)))
     {
         indexWriter.DeleteAll();
         types.ForEach(x =>
         {
             if (x.published != null && ((bool)x.published))
             {
                 Document doc = new Document();
                 doc.Add(new Field("typeID", "" + x.typeID, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO));
                 doc.Add(new Field("typeName", x.typeName, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
                 // doc.Add(new Field("description", , Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO));
                 indexWriter.AddDocument(doc);
             }
         });
      }
 }
开发者ID:karlbloedorn,项目名称:wpEVE,代码行数:18,代码来源:invTypeIndexRepository.cs

示例15: BuildIndex

        public void BuildIndex(List<User> users)
        {
            FSDirectory directory = FSDirectory.Open(new System.IO.DirectoryInfo(AppData));

            Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);

            IndexWriter indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);

            indexWriter.DeleteAll();

            foreach (User u in users)
            {
                indexWriter.AddDocument(u.GetDocument());
            }

            indexWriter.Optimize();
            indexWriter.Close();
        }
开发者ID:ucdavis,项目名称:WhoIs,代码行数:18,代码来源:UserSearchService.cs


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