Hi Tony Field Names are case sensitive. So i meant "FileName" <> "Filename" (see the "N") And not filename <> filename
DIGY -----Original Message----- From: tony njedeh [mailto:[EMAIL PROTECTED] Sent: Saturday, March 10, 2007 1:29 AM To: [email protected] Subject: RE: New to Apache Lucene.Net 2.0.0 Hi DIGY, What did you mean filename <> filename. I tried writing the code to show me the hits, with ---------------------------------------------------------------------------- ------------- "Response.Write("I found " & hits.Length & " values")" ---------------------------------------------------------------------------- ------------ And that also came out, not finding anything on the search results. I am aware my problem is with the indexing and search display but I cant point my finger on it. the c # code is below. ---------------------------------------------------------------------------- ------------------------------------------------------ Document doc = new Document(); Field f1 = new Field("FileName", DocumentPathToIndex, Field.Store.YES, Field.Index.NO); Field f2 = new Field("Text", rd.ReadToEnd, Field.Store.NO, Field.Index.TOKENIZED); doc.Add(f1); doc.Add(f2); ---------------------------------------------------------------------------- -------------------------------------------------------- I was wondering if the problem could be .txt files I had attached, if there is a specific format, I am to put text on the text files. one of the files named 5.txt has these contents ---------------------------------------------------------------------------- ------------------------------------------------------ day see the night day please day where 2) casinos in bombay 3) too much test 4) another line Day one is far day two rolls ---------------------------------------------------------------------------- ----------------------------------------------------- And the c# search code is ---------------------------------------------------------------------------- ------------------------------------------------- protected void searched(object sender, System.EventArgs e) { string Indexpath = "C:\\lucenex\\dump\\blabla\\"; string test = "day"; Search1(Indexpath, test); } private void Search1(string path, string TextToSearch) { bool createANewIndex = false; IndexSearcher searcher = new IndexSearcher(path); QueryParser queryParser = new QueryParser("text", new StandardAnalyzer()); Query query = queryParser.Parse(TextToSearch); Hits hits = searcher.Search(query); string s = ""; int i = 0; Response.Write("I found " + hits.Length + " values"); while (i < hits.Length) { s += hits.Doc(i).GetField("Filename").StringValue + "" + Microsoft.VisualBasic.Chr(10) + ""; System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1); Response.Write(s); Response.Write(hits.Doc(i).GetField("Filename").StringValue + "" + Microsoft.VisualBasic.Chr(10) + ""); Response.Write(hits.Doc(i).GetField("Text").StringValue + "" + Microsoft.VisualBasic.Chr(10) + ""); } ---------------------------------------------------------------------------- ------------------------------------------------- I am not sure if the the problem is, the search is not reading the text file. I truly am confused how to go about this. Anthony Digy <[EMAIL PROTECTED]> wrote: Hi Tony "FileName" <> "Filename" See indexing and searching codes I: Dim f1 As Field = New Field("FileName", DocumentPathToIndex, Field.Store.YES, Field.Index.NO) S: Response.Write(hits.Doc(i).GetField("Filename").StringValue + "" & Microsoft.VisualBasic.Chr(10) & "") DIGY From: tony njedeh [mailto:[EMAIL PROTECTED] Sent: Thursday, March 08, 2007 10:51 PM To: [email protected] Subject: RE: New to Apache Lucene.Net 2.0.0 Hello everyone, I built a test VB.Net code based on a template DIGY gave me and it works. The only problem I have is, I am unable to get hits from the search, when I use repeated terms. I did the search and I the results keeps coming back empty. I am pasting my code below, please could anyone help me find what's wrong with my code. I am also attaching the text files I used. ============Code Behind========================================== Imports Lucene.Net.Index Imports Lucene.Net.Documents Imports Lucene.Net.Analysis Imports Lucene.Net.Analysis.Standard Imports Lucene.Net.Search Imports Lucene.Net.QueryParsers Imports System.IO Partial Class lucenex Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim Indexpath As String = "C:\lucenex\dump\blabla" Dim createANewIndex As Boolean = True Dim writer As IndexWriter = New IndexWriter(Indexpath, New StandardAnalyzer, createANewIndex) 'New Code from digy starts here IndexDocument(writer, "C:\lucenex\dump\3.txt") IndexDocument(writer, "C:\lucenex\dump\5.txt") IndexDocument(writer, "C:\lucenex\dump\1.txt") writer.Close() ' Search(Indexpath, "day") End Sub Sub IndexDocument(ByVal writer As IndexWriter, ByVal DocumentPathToIndex As String) Dim rd As StreamReader = New StreamReader(DocumentPathToIndex) Dim doc As Document = New Document Dim f1 As Field = New Field("FileName", DocumentPathToIndex, Field.Store.YES, Field.Index.NO) Dim f2 As Field = New Field("Text", rd.ReadToEnd, Field.Store.NO, Field.Index.TOKENIZED) doc.Add(f1) doc.Add(f2) writer.AddDocument(doc) rd.Close() End Sub Private Sub Search(ByVal path As String, ByVal TextToSearch As String) Dim searcher As IndexSearcher = New IndexSearcher(path) Dim queryParser As QueryParser = New QueryParser("text", New Lucene.Net.Analysis.Standard.StandardAnalyzer) Dim query As Query = queryParser.Parse(TextToSearch) Dim hits As Hits = searcher.Search(query) Dim s As String = "" Dim i As Integer = 0 'Dim ant() As Array While i < hits.Length s += hits.Doc(i).GetField("Filename").StringValue + "" & Microsoft.VisualBasic.Chr(10) & "" System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) 'ant(i) = s Response.Write(hits.Doc(i).GetField("Filename").StringValue + "" & Microsoft.VisualBasic.Chr(10) & "") Response.Write(hits.Doc(i).GetField("Text").StringValue + "" & Microsoft.VisualBasic.Chr(10) & "") End While searcher.Close() Me.s.Text = s ' MsgBox1.alert(s) 'MessageBox.Show(s) End Sub Protected Sub searched(ByVal sender As Object, ByVal e As System.EventArgs) Handles sch.Click Dim Indexpath As String = "C:\lucenex\dump\blabla\" Search1(Indexpath, "day") End Sub Private Sub Search1(ByVal path As String, ByVal TextToSearch As String) Dim createANewIndex As Boolean = False 'Dim wtx As IndexWriter = New IndexWriter(path, New Lucene.Net.Analysis.Standard.StandardAnalyzer, createANewIndex) Dim searcher As IndexSearcher = New IndexSearcher(path) Dim queryParser As QueryParser = New QueryParser("text", New StandardAnalyzer) Dim query As Query = queryParser.Parse(TextToSearch) Dim hits As Hits = searcher.Search(query) Dim s As String = "" Dim i As Integer = 0 'Dim ant() As Array Response.Write("I found " & hits.Length & " values") While i < hits.Length s += hits.Doc(i).GetField("Filename").StringValue + "" & Microsoft.VisualBasic.Chr(10) & "" System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1) Response.Write(s) Response.Write(hits.Doc(i).GetField("Filename").StringValue + "" & Microsoft.VisualBasic.Chr(10) & "") Response.Write(hits.Doc(i).GetField("Text").StringValue + "" & Microsoft.VisualBasic.Chr(10) & "") End While searcher.Close() Me.s.Text = s ' MsgBox1.alert(s) 'MessageBox.Show(s) End Sub End Class ===================Presentation page ================================ Inherits="lucenex" %> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Thank You all. Tony Digy wrote: Hi Tony No diff. whether coding in WinForms or ASP.NET I prepared a simple example for you. DIGY private void Form1_Load(object sender, EventArgs e) { string IndexPath=@"c:\temp\blabla"; bool createANewIndex = true; //true:"New index" false:"use existing index" IndexWriter wr = new IndexWriter(IndexPath, new Lucene.Net.Analysis.Standard.StandardAnalyzer(), createANewIndex); IndexDocument(wr, @"c:\temp\somedoc1.txt"); IndexDocument(wr, @"c:\temp\somedoc2.txt"); wr.Close(); Search(IndexPath, "hakuna matata"); } void IndexDocument(IndexWriter wr,string DocumentPathToIndex) { StreamReader rd = new StreamReader(DocumentPathToIndex); Document doc = new Document(); Field f1 = new Field("FileName", DocumentPathToIndex, Field.Store.YES, Field.Index.NO); Field f2 = new Field("Text", rd.ReadToEnd(), Field.Store.NO, Field.Index.TOKENIZED); doc.Add(f1); doc.Add(f2); wr.AddDocument(doc); rd.Close(); } private void Search(string Path,string TextToSearch) { IndexSearcher searcher = new IndexSearcher(Path); QueryParser queryParser = new QueryParser("Text", new Lucene.Net.Analysis.Standard.StandardAnalyzer()); Query query = queryParser.Parse(TextToSearch); Hits hits = searcher.Search(query); string s = ""; for (int i = 0; i < hits.Length(); i++) { s += hits.Doc(i).GetField("FileName").StringValue() + "\n"; } searcher.Close(); MessageBox.Show(s); } -----Original Message----- From: tony njedeh [mailto:[EMAIL PROTECTED] Sent: Monday, March 05, 2007 10:11 PM To: [email protected] Subject: New to Apache Lucene.Net 2.0.0 Good Morning guys, I hope you all had a good weekend. I wanted to ask if anyone had a simple example of indexing and searching in ASP.net. I went through the code I downloaded from the site and the code for indexing and searching kept getting me confused. Thanks all, and please forgive my naive questions. Tony Ed Jones wrote: Tony, Try downloading the files from http://www.dotlucene.net/download/ simply download the ZIP file and look for the dll I the bin directory. Add as a reference in your VS.net project. Then take a look at the 5 tutorials here http://www.dotlucene.net/tutorial/ , they are in c# but you can use an online converter like this one: http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx I had the same learning curve as you and although I only dabbled with Lucene I got an indexer and searching system working quite quickly. Hope that helps Ed -----Original Message----- From: tony njedeh [mailto:[EMAIL PROTECTED] Sent: 02 March 2007 20:05 To: [email protected] Subject: RE: New to Apache Lucene.Net 2.0.0 Regarding the lucene.net.dll, am I to compile my files and get the .dll files or its provided on the website. And the first step, I would like to make is, indexing and building a test document I can search with. I am sorry for my elementary questions, I am very new to the lucene environment. Thank you Anthony Max Metral wrote: Sorry, my respose was leading but not informative. I would think you'd be better off including the .Net dll and leaving it in its original state. You should not need Java at all, unless you want to use the Lucene Index Explorer for debugging (which is nice). What is the next step you're trying to do? Index something? Build a test document? -----Original Message----- From: tony njedeh [mailto:[EMAIL PROTECTED] Sent: Friday, March 02, 2007 2:24 PM To: [email protected] Subject: RE: New to Apache Lucene.Net 2.0.0 The website I work on, is set up in VB and not C# Max Metral wrote: Why did you convert them? -----Original Message----- From: tony njedeh [mailto:[EMAIL PROTECTED] Sent: Friday, March 02, 2007 2:10 PM To: [email protected] Subject: New to Apache Lucene.Net 2.0.0 Hi everyone, I am new to lucene and I wanted to use the search engine in my VB.net(web application). I have converted the C# files I downloaded from the lucene.net 1.9.0.7 in the url http://www.dotlucene.net/ to VB files. I also downloaded Java 5. I was hoping, if you guys could guide me through the next steps to make, because I am seriously out of my element here. Thank you
