Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search a Field.Index.NOT_ANALYZED field in Lucene.NET?

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));
like image 770
muhammad kashif Avatar asked Jul 03 '13 09:07

muhammad kashif


1 Answers

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").

like image 195
sisve Avatar answered Oct 03 '22 18:10

sisve