ASP.NET - best practice for DB & File search with lucene.net in a asp.net web application

Asked By Tridip Bhattacharjee on 26-Jun-12 07:43 AM

i have site where i need to develop site search functionality. the data may reside in database table or may in aspx page as static word. i search google and found that lucene.net may be appropriate for the site search functionality. but i never use lucene.net so i dont know how to create lucene.net index file. i want to develop 2 utility in my site like

1) one for create & update index file reading data from database table & physical aspx file.

2) utility which search multiple single or multiple keyword against index file.

i found a bit of code snippet which i just do not understand

string indexFileLocation = @"C:\Index";
    string stopWordsLocation = @"C:\Stopwords.txt";
    var directory = FSDirectory.Open(new DirectoryInfo(indexFileLocation));
    Analyzer analyzer = new StandardAnalyzer(
      Lucene.Net.Util.Version.LUCENE_29, new FileInfo(stopWordsLocation));

what is Lucene.Net.Util.Version.LUCENE_29 what is stopWordsLocation how data need to store in Stopwords.txt

but have no concept to develop the above 2 utility.

here is my tables schema which i want to search by lucene.net

i like to create index just extract data from all the fields from the above 3 table and also need to extract static data from aspx page and store in lucene index file for search later.

    CREATE TABLE [Website_Content]
    (
    [PageTitle] [nvarchar](512)  NULL,
    [Description] [nvarchar](512)  NULL,
    [Keywords] [nvarchar](512)  NULL,
    [Content] [ntext]  NULL
    )

CREATE TABLE [Products]
(
    [ProductId] [int] IDENTITY(1,1) NOT NULL,
    [CategoryId] [int] NOT NULL,
    [Ref1] [varchar](32)  NULL ,
    [Ref2] [varchar](32)  NULL,
    [Title] [varchar](128)  NULL,
    [Year] [varchar](10)  NULL,
    [Description] [ntext]  NULL,
    [IsOwnUnitRebuild] [bit] NOT NULL,
    [PriceEx] [money] NOT NULL,
    [Surcharge] [money] NOT NULL,
    [Availability] [nvarchar](16)  NULL,
    [IsSellableOnline] [bit] NOT NULL,
    [DetailedProductID] [int] NOT NULL,
    [Siemens] [bit] NULL,
    [Features] [ntext]  NULL,
    [ProductInfo] [ntext]  NULL,
    [BoxContent] [ntext]  NULL,
    [Picture1] [image] NULL,
    [Picture2] [image] NULL,
    [Picture3] [image] NULL,
    [Picture4] [image] NULL,
    [VehicleApplication] [nvarchar](1024)  NULL,
    [FAQ] [ntext]  NULL,
    [EbayLink] [nvarchar](256)  NULL,
    [PriceExUS] [money] NULL,
    [Country] [varchar](50)  NULL,
    [PriceOUR] [money] NULL,
    [PriceOURUS] [money] NULL,
    [PriceEUR] [money] NULL ,
    [PriceOUREUR] [money] NULL
)


CREATE TABLE [DetailedProducts](
    [ProductId] [int] IDENTITY(1,1) NOT NULL,
    [Category] [int] NULL,
    [OERef] [nvarchar](32) NULL,
    [ManufacturerRef] [nvarchar](32)  NULL,
    [Title] [nvarchar](64)  NULL,
    [Year] [nvarchar](32)  NULL,
    [PriceEx] [money] NULL,
    [Options] [nvarchar](64)  NULL,
    [IsOwnUnitRebuilt] [bit] NULL,
    [Surcharge] [money] NULL,
    [Availability] [nvarchar](32)  NULL,
    [IsSellableOnline] [bit] NULL,
    [Features] [ntext]  NULL,
    [ProductInfo] [ntext]  NULL,
    [BoxContent] [ntext]  NULL,
    [Picture1] [image] NULL,
    [Picture2] [image] NULL,
    [Picture3] [image] NULL,
    [Picture4] [image] NULL,
    [VehicleApplication] [nvarchar](1024)  NULL,
    [FAQ] [ntext]  NULL,
    [EbayLink] [nvarchar](256)  NULL,
    [PriceExUS] [money] NULL,
    [Country] [varchar](50)  NULL,
    [PriceOUR] [money] NULL,
    [PriceOURUS] [money] NULL,
    [PriceEUR] [money] NULL ,
    [PriceOUREUR] [money] NULL
)

so please guide me how search my DB and as well as aspx files with lucene.net....i will be glad if some one discuss here with bit of sample code. thanks
Vikram Singh Saini replied to Tridip Bhattacharjee on 26-Jun-12 12:10 PM
It would be rather easy to help you by sharing links about Lucene.Net where authors have explained so nicely.

(1) http://www.codeproject.com/Articles/29755/Introducing-Lucene-Net

What exactly is Lucene.Net? What are the requirements for creating index? Such questions answers are on this link.

(2) http://www.codeproject.com/Articles/320219/Lucene-Net-ultra-fast-search-for-MVC-or-WebForms

Step-by-step implementation of Lucene.net can be found at this article with information on scenario, prerequisites.

(3) http://www.codeproject.com/Articles/30261/Lucene-net-in-asp-net-simple-example

Here is the ready made solution, that can be downloaded and can be used to work.

I would recommend to visit 2nd link first. That is the nice one in all of them.