Koerr
Koerr

Reputation: 15723

Can lucene search expression(Query Parser Syntax) search a NumericField filed?

I use NumericField write a Integer in lucene Index:

doc.add(
    new NumericField("id",Integer.MAX_VALUE,Field.Store.YES,true)
        .setIntValue(123)
);

Now I have a problem,How Can I write a search expression by id filed(NumericField)?

I tried:

id:123 and id:intToPrefixCoded(123)

but nothing for return

Reference:

Upvotes: 0

Views: 1089

Answers (1)

jpountz
jpountz

Reputation: 9964

This doesn't work because numeric fields' internal representation differs from their textual representation. You should either construct numeric queries manually or extend Lucene query parser. All you need to do is to extend the new*Query (Term, Range, ...) methods and have an if/else test on the field name to know whether you should create a numeric query or a regular query.

See Lucene wiki for more information.

Upvotes: 2

Related Questions