Lucene.NET returns results only when using numeric values

I used this code to create a Lucene.Net 2.9.2 index.

System.IO.DirectoryInfo indexFileLocation =
new System.IO.DirectoryInfo(textBox1.Text);
Lucene.Net.Store.Directory directory =
Lucene.Net.Store.FSDirectory.Open(indexFileLocation);
Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net
.Analysis
.Standard
.StandardAnalyzer(LuceneUtil.Version.LUCENE_29);
IndexWriter writer = new IndexWriter(directory, analyzer, true,
IndexWriter.MaxFieldLength.UNLIMITED);
foreach (IList item in dataToIndex)
{
Document doc = new Document();
doc.Add(new Field("ID", item[0].ToString(),
Field.Store.YES, Field.Index.NO));
....
string contents = item[0].ToString() + " " +
item[1].ToString() + " " ... ;
doc.Add(new Field("contents", contents,
Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
}
writer.Optimize();
writer.Close();

When I used this code to perform the search, it only returned results searching with numeric values.


Lucene.Net.Store.Directory directory = Lucene.Net
.Store
.FSDirectory.Open(new DirectoryInfo(textBoxSearchIndex.Text));


Lucene.Net.Search.IndexSearcher searcher =
new Lucene.Net.Search.IndexSearcher(directory, true);

Lucene.Net.Search.Query query =
new Lucene.Net.Search.TermQuery(searchTerm);
Lucene.Net.Search.Hits hits = searcher.Search(query);
Lucene.Net.Documents.Document doc = hits.Doc(i);
float score = hits.Score(i);
string result = “Score: ” + score.ToString() +
” contents: ” + doc.Get(“contents”);
When I changed it to the below logic, it worked. I received results with letters and-or numbers.


Lucene.Net.Store..Directory directory = Lucene.Net
.Store
.FSDirectory
.Open(new DirectoryInfo(textBoxSearchIndex.Text));
Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net
.Analysis
.Standard
.StandardAnalyzer(LuceneUtil.Version.LUCENE_29);
Lucene.Net.Search.Searcher searcher = new Lucene.Net
.Search
.IndexSearcher(LuceneIndex.IndexReader
.Open(directory, true));
Lucene.Net.Search.Query query = new Lucene.Net
.QueryParsers
.QueryParser(LuceneUtil.Version
.LUCENE_29, "contents", analyzer)
.Parse(textBoxSearch.Text);
Lucene.Net.Search.Hits hits = searcher.Search(query);
LuceneDocument.Document doc = hits.Doc(i);

I am just starting with Lucene.Net 2.9.2 so I am not sure why it worked with once procedure and not the other. If I find out at a later date then I will update this entry.