I am new to Lucene.NET. I am adding fields as
Field.Index.NOT_ANALYZED
in a Lucene document. There is one default field which is added in document as
Field.Index.ANALYZED
I have no difficulty in searching the default field; but when I search on a specific field then Lucene returns 0 document. However if I change,
Field.Index.NOT_ANALYZED
to
Field.Index.ANALYZED
then things work properly. I think there is something to do with Analyzer. Can any body guide me on how to search a Field.Index.NOT_ANALYZED
field?
Here is how I am creating the query parser:
QueryParser parser =
new QueryParser(
Version.LUCENE_30,
"content",
new StandardAnalyzer(Version.LUCENE_30));
ANALYZED
just means that the value is passed through an Analyzer before being indexed, while NOT_ANALYZED
means that the value will be indexed as-is. The later means that a value like "hello world" will be indexed as just exactly that, the string "hello world". However, the syntax for the QueryParser class parses spaces as a term-separator, creating two terms "hello" and "world".
You will be able to match the field if you created a var q = new TermQuery(new Term(field, "hello world"))
instead of calling var q = queryParser.Parse(field, "hello world")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With