0

I indexes documents with text and numbers. To create an index I use

 analyser = new SnowballAnalyzer(Version.LUCENE_30, "English"); 

I use Snoschballanalyzer because I need morphology(table - tables). When I search for text in the index - I find text, but don't find numeric value. I find one solution - Lucene - searching for a numeric value field, but it is necessary to create a separate field for numeric values. I now do not need to search a range of numeric values. I want to find a numeric value as a string. Example - source text:"He was born 1990 years". I need to find this tesxt on request "born" and "1990".

Community
  • 1
  • 1
FetFrumos
  • 5,388
  • 8
  • 60
  • 98

1 Answers1

1

You shouldnt have to do anything special.

Heres some code that does what you seem to want to achieve.

RAMDirectory dir = new RAMDirectory();
IndexWriter iw = new IndexWriter(dir, new SnowballAnalyzer(Lucene.Net.Util.Version.LUCENE_30,"English"), IndexWriter.MaxFieldLength.UNLIMITED);

Document d = new Document();
Field f = new Field("text", "", Field.Store.YES, Field.Index.ANALYZED);
d.Add(f);

f.SetValue("He was born 1990 years");
iw.AddDocument(d);

iw.Commit();
IndexReader reader = iw.GetReader();

IndexSearcher searcher = new IndexSearcher(reader);

QueryParser qp = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "text", new SnowballAnalyzer(Lucene.Net.Util.Version.LUCENE_30, "English"));
Query q = qp.Parse("+born +1990");

TopDocs td = searcher.Search(q, null, 25);
foreach (var sd in td.ScoreDocs)
{
    Console.WriteLine(searcher.Doc(sd.Doc).GetField("text").StringValue);
}

searcher.Dispose();
reader.Dispose();
iw.Dispose();
Jf Beaulac
  • 5,206
  • 1
  • 25
  • 46
  • Thank you. This cod works. My program works with two languages. When I searched for the number of languages ​​is not determined correctly. That's my problem.I will understand more. – FetFrumos May 08 '13 at 07:51