Nitin Varpe
Nitin Varpe

Reputation: 10704

NumericRangeFilter not working Lucene.net

I am trying to add search filter to products depending on price.

Lucene.Net.Search.Filter filter = NumericRangeFilter.NewFloatRange("AnalyzedPrice", minPrice, maxPrice, true, true);

But its Not returning any results. When I pass this filter as null output given is correct.

I am indexing my products' price using

doc.Add(new Field("AnalyzedPrice", pv.Price.ToString(), Field.Store.YES, Field.Index.ANALYZED));

Any Solutions?

Upvotes: 0

Views: 250

Answers (2)

Nitin Varpe
Nitin Varpe

Reputation: 10704

Following line solved my issue

doc.Add(new NumericField("AnalyzedPrice", Field.Store.YES, true).SetFloatValue((float)pv.Price));

Upvotes: 0

Lucas Trzesniewski
Lucas Trzesniewski

Reputation: 51430

You have to use the NumericField class for range queries to work (or FloatField for instance if you're using a more recent Lucene version through IKVM).

This class will encode your field data - it will not be stored textually anymore.

Upvotes: 1

Related Questions