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
Earn up to 50 extra points for answering this tough question.

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.
help
timefile = t.ToString().Replace(' / ', '_').Replace(':', '_'); String filenameis = Server.MapPath("kmlfiles \ kmlname" + timefile + ".txt"); FileInfo fileInfo = new FileInfo(filenameis); Response.Clear(); Response.AddHeader("Content-Disposition", "inline;attachment; filename = " +fileInfo); / / Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.ContentType = "application / octet-stream"; Response.Flush(); Response.WriteFile fileInfo.FullName)); Response.End(); this is giving me error in internet explored and with mozilla it is saving the file but without extension hello use this: FileInfo fileInfo = new FileInfo (filenameis); Response.Clear(); Response.AddHeader( "Content-Disposition" , "inline;attachment; filename = " + fileInfo.Name + ";" ); / / Response
I have a problem with System.IO.FileInfo. FileInfo fi = new FileInfo("testFile.txt"); Logger.Write(String.Format("isExist: {0}", fi.Exist() )); if (fi.Exist()) fi.Delete at all. Any help is appreciated. Thanks in advance regards, Andrew C# Discussions System.IO.FileInfo.Delete (1) FileInfo (1) String.Format (1) Logger.Write (1) Delete (1) Format (1) VisualStudio (1) IsExist (1 before I try to delete the file. Thanks in advance regards, Andrew keywords: System.IO.FileInfo.Delete() description: I have a problem with System.IO.FileInfo. FileInfo fi = new FileInfo(testFile.txt); Logger.Write(String.Format(isExist: {0}, fi.Exist() )); if
does one get the file size of a given text file? BR Mashao C# Discussions FileInfo (1) You can use System.IO.FileInfo example: System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"c: \ getmysize.txt"); / / write file length in bytes to textbox1 this.textBox1.Text = fileInfo.Length.ToString(); Hope this helps, Erik Hi, You can get the size of any file by using FileInfo.Length To get the size in bytes, you use the Length property of the FileInfo class, as others already have mentioned. If you want to know the size in characters
How to Convert ArrayList to FileInfo[]. . .Please Give any Example. . It's Urgent ArrayList sysFiles = new ArrayList(); FileInfo[] myFiles = (FileInfo[])(sysFiles.ToArray(typeof(FileInfo))); This is the correct VB version of the code. Works great, thanks! Friend Class FileInfoNameComparer x As Object , ByVal y As Object ) As Integer Implements IComparer. Compare Dim objX As FileInfo = CType (x, FileInfo) Dim objY As FileInfo = CType (y, FileInfo) Return objX.Name.CompareTo(objY.Name) End Function End Class Protected Sub
want to make empty the text file, if the file size = > 500KB. Any sample code? FileInfo fi = new FileInfo(path); long myFileLength = fi.Length; if(myFileLength > 500000 / *whatever length you want * / ) fi.Delete(); You can use System.IO.FileInfo example: System.IO.FileInfo fileInfo = new System.IO FileInfo(@"c: \ getmysize.txt"); / / write file length in bytes to textbox1 this.textBox1.Text = fileInfo.Length.ToString(); Hope this helps The above code is to get the lenght. . . . Hello JAmes System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"c: \ getmysize.txt"); / / write file length in bytes to textbox1
Can't use FileInfo in using statement? I have the following statement: using (FileInfo fInfo = new FileInfo(fromImagePath + " \ " + (string)dr["originalFileName"])) and I get the following error: 'System.IO.FileInfo': type used in a using statement must be implicitly convertible to 'System.IDisposable' I assume should I just let the garbage collector handle it? Thanks, Tom C# Discussions FileStream (1) FileInfo (1) IDisposable (1) OriginalFileName (1) FromImagePath (1) FInfo.Close (1) FInfo (1) Collector (1) No because it doesn't implement IDisposable. Do you see a Close method defined anywhere on FileInfo? What would you expect it to do? Yes. There are no unmanaged resource to release Depth: http: / / csharpindepth.com How would you know when to close the object? Doesn't FileInfo create an object and therefore resources? Then why does not it need to be closed
pls help me Thanks on click of that link button u can write the code FileInfo fileInfo = new FileInfo(filenameis); Response.Clear(); Response.AddHeader("Content-Disposition", "inline;attachment; filename = " + fileInfo.Name.Replace(" ", "_")); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.ContentType = "application / octet-stream"; Response.Flush(); Response.WriteFile fileInfo.FullName)); Response.End(); where i write the file name on click of link call javascript said. in filename you have to write the path of .pdf file. keywords: FileInfoASP.NET, FileInfo fileInfo, Disposition, AddHeader, WriteFile description: Pdf link with open and save menu hi friends, i am
Hello, I create a file using FileInfo by : NewFile = new FileInfo(FileName); and I got a parameter which tells me in which folder I need to How can I implement it on C# if I am getting _folderName and by using FileInfo instance ? Thank u! * ** Sent via Developersdex http: / / www.developersdex.com * ** C# Discussions StreamWriter (1) FileStream (1) FileInfo (1) Path.Combine (1) Path (1) Myfilename (1) Hi, I do not understand what you Machin http: / / www.laceupsolutions.com Mobile & warehouse Solutions. it is news to me that the FileInfo Class can create a new file. From my understanding, it only works with an existing file to obtain the file properties of the file. FileInfo does not create the file if it does not exist. Did I misunderstand your first want a full path based on _foldername and FileName, use Path.Combine(_foldername, FileName). keywords: FileInfo, question description: Hello, I create a file using FileInfo by : NewFile = new FileInfo(FileName); and
Hi, I have to create a search engine using Lucene.net for searching datas including text inside the files.So I use lucene.net.dll in vb.net wherein index is working but not the search. My code is here.Pls tell me what is to be changed . . . Imports Lucene.Net.Analysis Imports Lucene.Net.Documents Imports Lucene.Net.Documents.Field Imports Lucene.Net.Analysis.Standard Imports Lucene.Net.Index Imports Lucene.Net.search Imports Lucene.Net.QueryParsers Imports Lucene.Net.Util.StringHelper