Skip to content

Commit e1fc5ec

Browse files
author
Andrew Clegg
committed
Junked unused TimeZoneRoundingBuilder; added more comments
1 parent faa1fb7 commit e1fc5ec

File tree

8 files changed

+195
-21
lines changed

8 files changed

+195
-21
lines changed

src/main/java/com/pearson/entech/elasticsearch/search/facet/approx/date/external/DateFacetBuilder.java

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ public DateFacetBuilder(final String name) {
6262
}
6363

6464
/**
65-
* The field name to perform the histogram facet. Translates to perform the histogram facet
66-
* using the provided field as both the {@link #keyField(String)} and {@link #valueField(String)}.
65+
* The field name to use in order to control where the hit will "fall into" within the histogram
66+
* entries -- synonym for keyField(). Essentially, using the key field numeric value, the hit
67+
* will be "rounded" into the relevant bucket controlled by the interval.
68+
*
69+
* @param field
70+
* @return the builder
6771
*/
6872
public DateFacetBuilder field(final String field) {
6973
this.keyFieldName = field;
@@ -72,8 +76,11 @@ public DateFacetBuilder field(final String field) {
7276

7377
/**
7478
* The field name to use in order to control where the hit will "fall into" within the histogram
75-
* entries. Essentially, using the key field numeric value, the hit will be "rounded" into the relevant
76-
* bucket controlled by the interval.
79+
* entries -- synonym for field(). Essentially, using the key field numeric value, the hit
80+
* will be "rounded" into the relevant bucket controlled by the interval.
81+
*
82+
* @param keyField
83+
* @return the builder
7784
*/
7885
public DateFacetBuilder keyField(final String keyField) {
7986
this.keyFieldName = keyField;
@@ -83,6 +90,9 @@ public DateFacetBuilder keyField(final String keyField) {
8390
/**
8491
* The field name to use as the value of the hit to compute data based on values within the interval
8592
* (for example, total).
93+
*
94+
* @param valueField
95+
* @return the builder
8696
*/
8797
public DateFacetBuilder valueField(final String valueField) {
8898
this.valueFieldName = valueField;
@@ -91,25 +101,44 @@ public DateFacetBuilder valueField(final String valueField) {
91101

92102
/**
93103
* The field name to count distinct values of.
104+
*
105+
* @param distinctField
106+
* @return the builder
94107
*/
95108
public DateFacetBuilder distinctField(final String distinctField) {
96109
this.distinctFieldName = distinctField;
97110
return this;
98111
}
99112

100113
/**
101-
* The field name to slice the _output by.
114+
* The field name to slice the output by.
115+
*
116+
* @param sliceField
117+
* @return the builder
102118
*/
103119
public DateFacetBuilder sliceField(final String sliceField) {
104120
this.sliceFieldName = sliceField;
105121
return this;
106122
}
107123

124+
/**
125+
* A value script to apply -- NOT YET IMPLEMENTED.
126+
*
127+
* @param valueScript
128+
* @return the builder
129+
*/
108130
public DateFacetBuilder valueScript(final String valueScript) {
109131
this.valueScript = valueScript;
110132
return this;
111133
}
112134

135+
/**
136+
* Arbitrary additional parameters -- currently none are used.
137+
*
138+
* @param name the parameter name
139+
* @param value the parameter value
140+
* @return the builder
141+
*/
113142
public DateFacetBuilder param(final String name, final Object value) {
114143
if(params == null) {
115144
params = Maps.newHashMap();
@@ -119,7 +148,10 @@ public DateFacetBuilder param(final String name, final Object value) {
119148
}
120149

121150
/**
122-
* The language of the value script.
151+
* The language of the value script -- NOT YET IMPLEMENTED.
152+
*
153+
* @param lang the language
154+
* @return the builder
123155
*/
124156
public DateFacetBuilder lang(final String lang) {
125157
this.lang = lang;
@@ -129,6 +161,9 @@ public DateFacetBuilder lang(final String lang) {
129161
/**
130162
* The interval used to control the bucket "size" where each key value of a hit will fall into. Check
131163
* the docs for all available values.
164+
*
165+
* @param interval the interval setting
166+
* @return the builder
132167
*/
133168
public DateFacetBuilder interval(final String interval) {
134169
this.interval = interval;
@@ -137,6 +172,9 @@ public DateFacetBuilder interval(final String interval) {
137172

138173
/**
139174
* Should pre zone be adjusted for large (day and above) intervals. Defaults to <tt>false</tt>.
175+
*
176+
* @param preZoneAdjustLargeInterval true/false
177+
* @return the builder
140178
*/
141179
public DateFacetBuilder preZoneAdjustLargeInterval(final boolean preZoneAdjustLargeInterval) {
142180
this.preZoneAdjustLargeInterval = preZoneAdjustLargeInterval;
@@ -149,6 +187,9 @@ public DateFacetBuilder preZoneAdjustLargeInterval(final boolean preZoneAdjustLa
149187
* <p/>
150188
* Can either be in the form of "-10:00" or
151189
* one of the values listed here: http://joda-time.sourceforge.net/timezones.html.
190+
*
191+
* @param preZone a timezone string
192+
* @return the builder
152193
*/
153194
public DateFacetBuilder preZone(final String preZone) {
154195
this.preZone = preZone;
@@ -161,6 +202,9 @@ public DateFacetBuilder preZone(final String preZone) {
161202
* <p/>
162203
* Can either be in the form of "-10:00" or
163204
* one of the values listed here: http://joda-time.sourceforge.net/timezones.html.
205+
*
206+
* @param postZone a timezone string
207+
* @return the builder
164208
*/
165209
public DateFacetBuilder postZone(final String postZone) {
166210
this.postZone = postZone;
@@ -169,6 +213,9 @@ public DateFacetBuilder postZone(final String postZone) {
169213

170214
/**
171215
* Sets a pre offset that will be applied before rounding the results.
216+
*
217+
* @param preOffset a valid time value
218+
* @return the builder
172219
*/
173220
public DateFacetBuilder preOffset(final TimeValue preOffset) {
174221
this.preOffset = preOffset.millis();
@@ -177,6 +224,9 @@ public DateFacetBuilder preOffset(final TimeValue preOffset) {
177224

178225
/**
179226
* Sets a post offset that will be applied after rounding the results.
227+
*
228+
* @param postOffset a valid time value
229+
* @return the builder
180230
*/
181231
public DateFacetBuilder postOffset(final TimeValue postOffset) {
182232
this.postOffset = postOffset.millis();
@@ -186,6 +236,9 @@ public DateFacetBuilder postOffset(final TimeValue postOffset) {
186236
/**
187237
* Sets the factor that will be used to multiply the value with before and divided
188238
* by after the rounding of the results.
239+
*
240+
* @param factor the rounding factor
241+
* @return the builder
189242
*/
190243
public DateFacetBuilder factor(final float factor) {
191244
this.factor = factor;
@@ -195,6 +248,9 @@ public DateFacetBuilder factor(final float factor) {
195248
/**
196249
* How many distinct terms can we collect in each result bucket before
197250
* flipping over to approximate counting? (Distinct mode only)
251+
*
252+
* @param threshold the threshold
253+
* @return the builder
198254
*/
199255
public DateFacetBuilder exactThreshold(final int threshold) {
200256
this.exactThreshold = threshold;
@@ -204,6 +260,9 @@ public DateFacetBuilder exactThreshold(final int threshold) {
204260
/**
205261
* Should the facet run in global mode (not bounded by the search query) or not (bounded by
206262
* the search query). Defaults to <tt>false</tt>.
263+
*
264+
* @param global true/false
265+
* @return the builder
207266
*/
208267
@Override
209268
public DateFacetBuilder global(final boolean global) {
@@ -213,6 +272,9 @@ public DateFacetBuilder global(final boolean global) {
213272

214273
/**
215274
* An additional filter used to further filter down the set of documents the facet will run on.
275+
*
276+
* @param the filter to use
277+
* @return the builder
216278
*/
217279
@Override
218280
public DateFacetBuilder facetFilter(final FilterBuilder filter) {
@@ -223,6 +285,9 @@ public DateFacetBuilder facetFilter(final FilterBuilder filter) {
223285
/**
224286
* Sets the nested path the facet will execute on. A match (root object) will then cause all the
225287
* nested objects matching the path to be computed into the facet.
288+
*
289+
* @param nested a nested path using dot notation
290+
* @return the builder
226291
*/
227292
@Override
228293
public DateFacetBuilder nested(final String nested) {

src/main/java/com/pearson/entech/elasticsearch/search/facet/approx/date/external/DistinctSlice.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@
44

55
import org.elasticsearch.common.xcontent.XContentBuilder;
66

7-
7+
/**
8+
* A slice which reports distinct values.
9+
*
10+
* @param <L> the data type of the slice label
11+
*/
812
public class DistinctSlice<L> extends Slice<L> implements HasDistinct {
913

1014
private final long _distinctCount;
1115

16+
/**
17+
* Create a new DistinctSlice.
18+
*
19+
* @param label the slice label to use
20+
* @param count the count of values in this slice
21+
* @param distinctCount the count of distinct values in this slice
22+
*/
1223
public DistinctSlice(final L label, final long count, final long distinctCount) {
1324
super(label, count);
1425
_distinctCount = distinctCount;

src/main/java/com/pearson/entech/elasticsearch/search/facet/approx/date/external/DistinctTimePeriod.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,34 @@
55
import org.elasticsearch.common.xcontent.ToXContent;
66
import org.elasticsearch.common.xcontent.XContentBuilder;
77

8-
8+
/**
9+
* A time period which reports distinct values.
10+
*
11+
* @param <E> the data type of the time period entry
12+
*/
913
public class DistinctTimePeriod<E extends ToXContent> extends TimePeriod<E> {
1014

1115
private final long _distinctCount;
1216

13-
public DistinctTimePeriod(final long time, final long totalCount,
17+
/**
18+
* Create a new DistinctTimePeriod.
19+
*
20+
* @param time the timestamp of this period
21+
* @param count the count of values in this period
22+
* @param distinctCount the count of distinct values in this period
23+
* @param entry the actual facet entry for this time period
24+
*/
25+
public DistinctTimePeriod(final long time, final long count,
1426
final long distinctCount, final E entry) {
15-
super(time, totalCount, entry);
27+
super(time, count, entry);
1628
_distinctCount = distinctCount;
1729
}
1830

31+
/**
32+
* Get the distinct count for this time period.
33+
*
34+
* @return the distinct count
35+
*/
1936
public long getDistinctCount() {
2037
return _distinctCount;
2138
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package com.pearson.entech.elasticsearch.search.facet.approx.date.external;
22

3+
/**
4+
* An interface for objects which report a distinct count.
5+
*/
36
public interface HasDistinct {
47

8+
/**
9+
* Get the distinct count.
10+
*
11+
* @return the distinct count
12+
*/
513
long getDistinctCount();
614

715
}

src/main/java/com/pearson/entech/elasticsearch/search/facet/approx/date/external/NullEntry.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
import org.elasticsearch.common.xcontent.ToXContent;
66
import org.elasticsearch.common.xcontent.XContentBuilder;
77

8+
/**
9+
* A placeholder for use in facets which don't have any individual entries.
10+
* Follows the enum singleton pattern. Just implements a no-op toXContent() call.
11+
*/
812
public enum NullEntry implements ToXContent {
913

14+
/**
15+
* The only instance of NullEntry you'll ever need.
16+
*/
1017
INSTANCE;
1118

1219
@Override

src/main/java/com/pearson/entech/elasticsearch/search/facet/approx/date/external/Slice.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,41 @@
55
import org.elasticsearch.common.xcontent.ToXContent;
66
import org.elasticsearch.common.xcontent.XContentBuilder;
77

8-
8+
/**
9+
* A slice in a sliced facet.
10+
*
11+
* @param <L> the data type of the slice label
12+
*/
913
public class Slice<L> implements ToXContent {
1014

1115
private final L _label;
1216
private final long _totalCount;
1317

18+
/**
19+
* Create a new slice.
20+
*
21+
* @param label the label
22+
* @param totalCount the count of values in this slice
23+
*/
1424
public Slice(final L label, final long totalCount) {
1525
_label = label;
1626
_totalCount = totalCount;
1727
}
1828

29+
/**
30+
* Get the label for this slice.
31+
*
32+
* @return the label
33+
*/
1934
public L getLabel() {
2035
return _label;
2136
}
2237

38+
/**
39+
* Get the value count for this slice.
40+
*
41+
* @return the count
42+
*/
2343
public long getTotalCount() {
2444
return _totalCount;
2545
}
@@ -34,8 +54,14 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
3454
return builder;
3555
}
3656

37-
protected void injectSliceXContent(final XContentBuilder builder) throws IOException {
38-
// override to add extra content in a slice object
39-
}
57+
/**
58+
* Override this method to inject additional fields after the label and count,
59+
* e.g. distinct counts. This method will be called at the appropriate time
60+
* by Slice's own toXContent() method.
61+
*
62+
* @param builder an XContentBuilder to use
63+
* @throws IOException
64+
*/
65+
protected void injectSliceXContent(final XContentBuilder builder) throws IOException {}
4066

4167
}

0 commit comments

Comments
 (0)