Click here to Skip to main content
15,885,908 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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:
C#
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

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?
Posted
Updated 24-Jul-14 23:24pm
v2

1 solution

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![^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900