• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
雪飞夏日
博客园    首页    新随笔    联系   管理    订阅  订阅
一个简单的工作流引擎实例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lucene.Net.Analysis;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Util;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Lucene.Net.Analysis.Standard;

namespace ConsoleLucene
{
    class Program
    {
        static void Main(string[] args)
        {
           
            //创建一个分析器
            Analyzer analyzer = new StandardAnalyzer();
            //创建一个索引的硬盘
            Directory directory = new RAMDirectory ();
            //将索引写入目录硬盘
            IndexWriter iwriter = new IndexWriter(directory,analyzer,true );
            iwriter.SetMaxFieldLength (25000);
            Document doc = new Document();
            string text = "this is the text to be indexed.";
            doc.Add(new Field("fieldname",text,Field.Store.YES,Field.Index.TOKENIZED ));
            iwriter.AddDocument(doc);
            iwriter.Close();
            //查询索引
            IndexSearcher isearcher = new IndexSearcher(directory);
            //解析查询
            Query query = QueryParser.Parse("text", "fieldname", analyzer);
            Hits hits = isearcher.Search(query);
            for (int i = 0; i < hits.Length(); i++) {
                Document hitDoc = hits.Doc(i);
                Console.WriteLine(hitDoc.GetField("fieldname").ToString());
            }
            isearcher.Close();
            directory.Close();
            Console.ReadLine();
        }
    }
}

posted on 2009-07-06 15:20  雪飞夏日  阅读(243)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3