Class DynamicRangeFacetsExample

java.lang.Object
org.apache.lucene.demo.facet.DynamicRangeFacetsExample

public class DynamicRangeFacetsExample extends Object
Demo dynamic range faceting.

The results look like so: min: 63 max: 75 centroid: 69.000000 count: 2 weight: 137 min: 79 max: 96 centroid: 86.000000 count: 3 weight: 83

We've computed dynamic ranges over popularity weighted by number of books. We can read the results as so: There are 137 books written by authors in the 63 to 75 popularity range.

How it works: We collect all the values (popularity) and their weights (book counts). We sort the values and find the approximate weight per range. In this case the total weight is 220 (total books by all authors) and we want 2 ranges, so we're aiming for 110 books in each range. We add Chesterton to the first range, since he is the least popular author. He's written a lot of books, the range's weight is 90. We add Tolstoy to the first range, since he is next in line of popularity. He's written another 47 books, which brings the total weight to 137. We're over the 110 target weight, so we stop and add everyone left to the second range.