zoukankan      html  css  js  c++  java
  • Lucene.Net 2.3.2

    Lucnee:全文信息检索工具包

    (1)下载svn客户端 url【http://tortoisesvn.net/downloads。】中文补丁包,安装,重启电脑。

    (2)新建文件夹 D:\Src\Lucene\Lucene.Net,右键SVN检出,url框输入url【https://svn.apache.org/repos/asf/incubator/lucene.net/trunk/】,下载Lucene。

    (3)打开项目文件Lucene.net-2.3.2. 缺少引用ICSharpCode.SharpZipLib??????????

    (4) 下载url:【http://www.icsharpcode.net/OpenSource/SharpZipLib/】dll包。再次添加引用,编译项目。ok。

    (5)创建一个C#控制台程序。对Lucene.Net的操作分为建立索引,和搜索两部分???

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        //索引
        using Lucene.Net.Index;
        using Lucene.Net.Store;
    
        using Lucene.Net.Documents;
        //分析
        using Lucene.Net.Analysis;
        using Lucene.Net.Analysis.Standard;
        //搜索
        using Lucene.Net.Search;
        using Lucene.Net.QueryParsers;
    
        class Program
        {
            static void Main(string[] args)
            {
                //建立索引
                CreateIndex();
                //搜索索引
                SearchIndex();
            }
    
            #region Search Index
    
            private static void SearchIndex()
            {
                Analyzer analyzer = new StandardAnalyzer();
                IndexSearcher searcher = new IndexSearcher("IndexDirectory");
    
                MultiFieldQueryParser parse = new MultiFieldQueryParser(new string[] { "title", "content" }, analyzer);
                Query query = parse.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.Read();
            }
    
            #endregion
    
            #region Create Index
    
            private static void CreateIndex()
            {
                Analyzer analyzer = new StandardAnalyzer();
                IndexWriter writer = new IndexWriter("IndexDirectory", analyzer, true);
                AddDocument(writer, "SQL 2008 发布_Title", "SQL 2008 新特性_content");
                AddDocument(writer, "Asp.net mvc_Title", "mvc 框架发布_content");
                writer.Optimize();
                writer.Close();
            }
    
            private 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);
            }
    
            #endregion
        }
    }

    运行:title :xx.. content: xx………(略)

    D:\Src\Lucene\Demo\Demo1\ConsoleApplication1\bin\Debug\IndexDirectory

    存放着3个文件 _1.cfs  、segments.gen 、segmaents_6 不知道干嘛的。

  • 相关阅读:
    volatile关键字
    线程的状态
    java中的匿名内部类
    java高精度实数和小数
    JS、JSP、ASP、CGI
    论文结构要求
    java中的标识符、关键字、保留字
    java IODemo
    Bagging和Boosting的区别
    由Memcached升级到 Couchbase的 Java 客户端的过程记录(一)
  • 原文地址:https://www.cnblogs.com/chinaniit/p/1505811.html
Copyright © 2011-2022 走看看