首先,我们先把我们要开始分解的程序的代码贴出来先。

以下的代码是yurow birdshover 这位网友的。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lucene.Net.Index;
using Lucene.Net.Store;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;

namespace LuceneText
{
    
class Program
    {
        
static void Main(string[] args)
        {
            Analyzer analyzer 
= new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
            
            
/// 建立索引
            IndexWriter writer = new IndexWriter("IndexDirectory", analyzer, true);
            AddDocument(writer, 
"SQL Server 2008的发布""SQL Server 2008的新特征");
            AddDocument(writer, 
"ASP.Net MVC框架配置与分析""而今,微软推出了新的MVC开发框架,也就是Microsoft ASP.NET 3.5 Extensions");
            writer.Optimize();
            writer.Close();


            
///搜索索引
            //IndexSearcher searcher = new IndexSearcher("IndexDirectory");
            
//MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new string[] { "title", "content" }, analyzer);
            
//Query query = parser.Parse("sql");
            
//Hits hits = searcher.Search(query);
            
//for (int i = 0; i < hits.Length(); i++)
            
//{
            
//    Document doc = hits.Doc(i);
            
//    Console.WriteLine(string.Format("title;{0} content:{1}", doc.Get("title"), doc.Get("content")));
            
//}
            
//searcher.Close();

            
//Console.ReadKey();
        }

        
static void AddDocument(IndexWriter writer, string title, string content)
        {
            Document document 
= new Document();
            document.Add(
new Field("title", title, Field.Store.YES, Field.Index.TOKENIZED));
            document.Add(
new Field("content", content, Field.Store.YES, Field.Index.TOKENIZED));
            writer.AddDocument(document);
        }
    }
}

相关文章:

  • 2022-01-17
  • 2022-01-01
  • 2021-12-08
  • 2021-07-28
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-10-31
猜你喜欢
  • 2021-10-21
  • 2022-02-08
相关资源
相似解决方案