You can not make searches on a field (using QueryParser) that is not
analyzed. (you can use TermQuery for the fields that are not analyzed
(considering the exact casing)).

DIGY.

-----Original Message-----
From: Ron Grabowski [mailto:rongrabow...@yahoo.com] 
Sent: Saturday, October 31, 2009 12:53 AM
To: lucene-net-user@incubator.apache.org
Subject: Must Field.Index.ANALYZED Fields be searched only by
QueryParser/StandardAnalyzer?

I'm confused why I my last two examples fail (/tags/Lucene.Net_2_4_0). They
don't return any hits  even though I'm searching on the exact name:

Directory directory = new RAMDirectory();

IndexWriter indexWriter = new IndexWriter(
    directory,
    new StandardAnalyzer(),
    IndexWriter.MaxFieldLength.UNLIMITED);
string name = "ACME Produce";
Document document = new Document();
document.Add(new Field("alayzed_name", name, Field.Store.YES,
Field.Index.ANALYZED));
document.Add(new Field("not_analyzed_name", name, Field.Store.YES,
Field.Index.NOT_ANALYZED));
indexWriter.AddDocument(document);
indexWriter.Close();

IndexSearcher searcher = new IndexSearcher(directory);

// works as expected...1 hit
QueryParser parser = new QueryParser("alayzed_name", new
StandardAnalyzer());
TopDocs topDocs = searcher.Search(parser.Parse("ACME Produce"), 1);
int totalHits = topDocs.totalHits;

// does not work...0 hits
parser = new QueryParser("not_analyzed_name", new StandardAnalyzer());
topDocs = searcher.Search(parser.Parse("ACME Produce"), 1);
totalHits = topDocs.totalHits;

// does not work...0 hits
parser = new QueryParser("not_analyzed_name", new StandardAnalyzer());
topDocs = searcher.Search(parser.Parse("acme produce"), 1);
totalHits = topDocs.totalHits;

Reply via email to