如何使用lucene.net进行C#Web应用程序 [英] How to use lucene.net for C# Web application

查看:96
本文介绍了如何使用lucene.net进行C#Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要为'D:\'驱动器创建本地搜索引擎。在我注入关键字或字符串的地方,系统应该在目录文件中搜索注入(D:\Dir \ ...),尽管有文件扩展名。



我从朋友那里倾向于关于Lucene.net,但我不知道如何从头开始使用它。是否有任何文章可以帮助我理解Lucene.net并使用它来搜索本地驱动器?

到目前为止,我已经创建了一个目录中的文件搜索,如下所示:

Hi I need to create a local search engine for a 'D:\' drive. Where I inject a keyword or string and the system should search that injection inside the files of the directories (D:\Dir\...) despite of the file extension.

I leaned about Lucene.net from friends but I don't know how to use it from scratch. Is there any article which would help me to understand Lucene.net and use it to search local drives?
So far I have created a search for files in a directory as follows:

protected void SearchButton_Click(object sender, EventArgs e)
    {

        string dir = @"D:\file path\";    
        //visibility true
        SearchResultPanel.Visible = true;

        try
        {
            //Set the current directory.
            Directory.SetCurrentDirectory(dir);

            //search all files in path
            string[] directoryEntries = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories);
            int fill = directoryEntries.Length - 1;

            //Total count of files & Decoration 
            SearchResultPanel.Controls.Add(new LiteralControl("<br />"));
            Label leb = new Label();
            SearchResultPanel.Controls.Add(new LiteralControl("The total files count: "));
            leb.Text = directoryEntries.Length.ToString();
            this.SearchResultPanel.Controls.Add(leb);
            SearchResultPanel.Controls.Add(new LiteralControl("<hr />"));

            //retriving the files in new labels
            for (int i = 0; i < fill; i++)
            {
                TextBox NewText = new TextBox();
                NewText.BorderStyle = BorderStyle.NotSet;
                NewText.TextMode = TextBoxMode.MultiLine;
                NewText.Width = 444;
                NewText.Height = 40;

                //Convert the file entries to text
                NewText.Text = directoryEntries[i];

                //new line
                SearchResultPanel.Controls.Add(new LiteralControl("<br />"));
                this.SearchResultPanel.Controls.Add(NewText);
            }//end of for

        }//end of try
        catch (DirectoryNotFoundException ex)
        {
            Console.WriteLine("The specified directory does not exist. {0}", ex);
        }
    }// end of SearchButton_Click() method



这显示了文件及其路径,但是如何应用lucene来搜索文档中的关键字或短语,并在一个文本框中返回特定文档路径,在其他文本框中返回关联的关键字示例文本?


This shows me the files and their path but how to apply lucene to search the keyword or phrase inside the documents and return perticular document path in one textbox and serached keyword sample text in other textbox?

推荐答案

Lucene.Net上有大量的文章和教程你需要做的搜索。



以下是一个很棒的首发。



Lucene.Net超快速搜索MVC或WebForms站点=>变得简单! [ ^ ]
There are tons of articles and tutorials on Lucene.Net all you have to do search.

The following is a great starter.

Lucene.Net ultra fast search for MVC or WebForms site => made easy![^]


这篇关于如何使用lucene.net进行C#Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆