RangeFacetHandler

Nov 13, 2014 at 4:39 PM
Edited Nov 13, 2014 at 4:39 PM
Hi all, could anyone show me an example of the usage of RangeFacetHandler?

I've already tried to test the handler with no success.
These are the settings I have adopted:
1) Field declaration:
Document doc = new Document();
doc.Add(new NumericField("number").SetIntValue(number));
doc.Add(new Field("date", DateTools.DateToString(date, DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new NumericField("price").SetDoubleValue(price));
2) Handler declaration:
string number = "number";
string date = "date";
string price = "price";
FacetHandler numberFacetHandler = new RangeFacetHandler(number, true);
FacetHandler dateFacetHandler = new RangeFacetHandler(date, true);
FacetHandler priceFacetHandler = new RangeFacetHandler(price, true);
As result on simple Lucene index, I have obtained:

Facets for number:
  • [ ☺ TO ☺] (2)
  • [ ☻ TO ☻] (3)
  • [ ♥ TO ♥] (2)
  • [ ♦ TO ♦] (2)
  • [ 2 TO 2] (1)
  • [ TO ] (10)
  • [d@ TO d@ ] (9)
  • [d@ ♥ TO d@ ♥] (1)
  • [h♦ TO h♦ ] (10)
  • [l TO l ] (10)
  • [p☻ TO p☻ ] (10)
  • [t► TO t► ] (10)
  • [x☺ TO x☺ ] (10)
Facets for date:
  • [19980102 TO 19980102] (1)
  • [20100212 TO 20100212] (1)
  • [20100703 TO 20100703] (1)
  • [20110610 TO 20110610] (1)
  • [20110710 TO 20110710] (1)
  • [20140101 TO 20140101] (1)
  • [20140201 TO 20140201] (4)
Facets for price:
  • [ ☺@$` TO ☺@♫W♣☼. ▲\] (10)
  • [$♀♣ $3↓Lf3 TO $♀ u8(zpQu] (10)
  • [(2Bvnk↔ TO (▬'DMi<5] (10)
  • [,♠☺‼ TO ,♠☺↕↓Lf3↓] (10)
  • [@♀♣ $3 TO @♀ u8(] (10)
  • [\♀ TO <☺@Q¶F3] (19)
  • [<☺@♫W♣☼ TO 00♥Ua#kB] (10)
  • [00♦Y!;75 TO 4♥ I@ ] (10)
  • [4♥ Y▲↕7% TO 8↑♦L ] (8)
  • [z► TO D`↕0 ] (12)
  • [D`▬'D TO H♠☻DR] (10)
  • [H♠ K¶ TO L0♥U] (10)
  • [L0♦Y TO P♥ Y] (11)
  • [T↑☺ TO X☺@] (20)
that has no sense to me. Is seems that the RangeFacetHandler exploits the internal Lucene representation for numbers and dates that is unreadable.

Thanks,
Diego
Coordinator
Nov 17, 2014 at 2:50 PM
Facets for dates actually look good to me in your example. Why do you think it is not right?

For numeric values try this instead:
        protected void AddValue(string name, int value)
        {
            NumericField field = new NumericField(name, 0x20, Field.Store.YES, true);
            document.Add(field.SetIntValue(value));
        }

        protected void AddValue(string name, double value)
        {
            NumericField field = new NumericField(name, 0x40, Field.Store.YES, true);
            document.Add(field.SetDoubleValue(value));
        }