• 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 不知道干嘛的。

  • 相关阅读:
    1 基本概念 进入java世界
    一文了解kudu【转载】
    jenkins git项目clean before checkout 和 wipe out repository & force clone
    jenkins 内置判断条件
    jenkins常用插件使用说明-git publisher
    常用正则表达式
    基于ldap+sentry+rbac的hive数据库权限测试
    nginx_mirror_module流量复制在项目中的应用
    jenkins上job误删除怎么恢复
    pipeline语法学习日记
  • 原文地址:https://www.cnblogs.com/chinaniit/p/1505811.html
Copyright © 2020-2023  润新知