lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nicholas Paldino [.NET/C# MVP]" <casper...@caspershouse.com>
Subject RE: need some help =)
Date Wed, 17 Nov 2010 19:32:43 GMT
	Why are you adding the bytes as the field value?  You should add the fields as strings and
you should be fine.

	Also, note that most people won't respond to this kind of code because it is not easily digestable.

-----Original Message-----
From: asmcad [mailto:asmcad@gmail.com] 
Sent: Wednesday, November 17, 2010 3:02 PM
To: lucene-net-dev
Subject: need some help =)


it's a simple index and search application but i couldn't make it work. 
it doesn't give any error but it  doesn't give any results too.

   1.
      using System;
   2.
      using System.Collections.Generic;
   3.
      using System.ComponentModel;
   4.
      using System.Data;
   5.
      using System.Drawing;
   6.
      using System.Linq;
   7.
      using System.Text;
   8.
      using System.Windows.Forms;
   9.
      using Lucene.Net;
  10.
      using Lucene.Net.Analysis.Standard;
  11.
      using Lucene.Net.Documents;
  12.
      using Lucene.Net.Index;
  13.
      using Lucene.Net.QueryParsers;
  14.
      using Lucene.Net.Search;
  15.
      using System.IO;
  16.
  17.
      namespace newLucene
  18.
      {
  19.
      public partial class Form1 : Form
  20.
      {
  21.
      public Form1()
  22.
      {
  23.
                   InitializeComponent();
  24.
      }
  25.
  26.
      private void buttonIndex_Click(object sender, EventArgs e)
  27.
      {
  28.
                   IndexWriter indexwrtr = new
      IndexWriter(@"c:\index\",new StandardAnalyzer() , true);
  29.
                   Document doc = new Document();
  30.
      string filename = @"fer.txt";
  31.
                   Lucene.Net.QueryParsers.QueryParser df;
  32.
  33.
  34.
  35.
      System.IO.StreamReader local_StreamReader = new
      System.IO.StreamReader(@"C:\z\fer.txt");
  36.
      string  file_text = local_StreamReader.ReadToEnd();
  37.
  38.
      System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
  39.
                   doc.Add(new
      Field("text",encoding.GetBytes(file_text),Field.Store.YES));
  40.
                   doc.Add(new
      Field("path",encoding.GetBytes(@"C:\z\"),Field.Store.YES));
  41.
                   doc.Add(new Field("title",
      encoding.GetBytes(filename), Field.Store.YES));
  42.
                   indexwrtr.AddDocument(doc);
  43.
  44.
                   indexwrtr.Optimize();
  45.
                   indexwrtr.Close();
  46.
  47.
      }
  48.
  49.
      private void buttonSearch_Click(object sender, EventArgs e)
  50.
      {
  51.
                   IndexSearcher indxsearcher = new
      IndexSearcher(@"C:\index\");
  52.
  53.
                   QueryParser parser = new QueryParser("contents", new
      StandardAnalyzer());
  54.
                   Query query = parser.Parse(textBoxQuery.Text);
  55.
  56.
      //Lucene.Net.QueryParsers.QueryParser qp = new
      QueryParser(Lucene.Net.QueryParsers.CharStream
      s).Parse(textBoxQuery.Text);
  57.
                   Hits hits = indxsearcher.Search(query);
  58.
  59.
  60.
      for (int i = 0; i < hits.Length(); i++)
  61.
      {
  62.
  63.
                       Document doc = hits.Doc(i);
  64.
  65.
  66.
      string filename = doc.Get("title");
  67.
      string path = doc.Get("path");
  68.
      string folder = Path.GetDirectoryName(path);
  69.
  70.
  71.
                       ListViewItem item = new ListViewItem(new string[]
      { null, filename, "asd", hits.Score(i).ToString() });
  72.
                       item.Tag = path;
  73.
  74.
      this.listViewResults.Items.Add(item);
  75.
                       Application.DoEvents();
  76.
      }
  77.
  78.
                   indxsearcher.Close();
  79.
  80.
  81.
  82.
  83.
      }
  84.
      }
  85.
      }


thanks




Mime
View raw message