-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added parameter "additional_grouping" for geohashcell facet. When this parameter is provided, the region counts are additionaly broken down according to terms in this field.
- Loading branch information
Showing
10 changed files
with
301 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
src/main/java/org/elasticsearch/plugin/geohashcellfacet/GeoHashCellFacetEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package org.elasticsearch.plugin.geohashcellfacet; | ||
|
||
import com.sun.tools.corba.se.idl.InterfaceState; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public interface GeoHashCellFacetEntry { | ||
XContentBuilder toXContent(XContentBuilder builder, AtomicLong value) throws IOException; | ||
ResultWithGroupings createCellWithGroupings(AtomicLong value); | ||
|
||
String getKey(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/org/elasticsearch/plugin/geohashcellfacet/GeoHashCellFacetResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.elasticsearch.plugin.geohashcellfacet; | ||
|
||
import org.elasticsearch.common.collect.Maps; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class GeoHashCellFacetResult { | ||
|
||
private final Map<String, ResultWithGroupings> counts; | ||
|
||
public GeoHashCellFacetResult() { | ||
this.counts = Maps.newHashMap(); | ||
} | ||
|
||
public GeoHashCellFacetResult(GeoHashCellFacetEntry entry, AtomicLong value) { | ||
Map<String, ResultWithGroupings> counts = Maps.newHashMap(); | ||
counts.put(entry.getKey(), entry.createCellWithGroupings(value)); | ||
|
||
this.counts = counts; | ||
} | ||
|
||
private GeoHashCellFacetResult(Map<String, ResultWithGroupings> counts) { | ||
this.counts = Maps.newHashMap(counts); | ||
} | ||
|
||
public GeoHashCellFacetResult reduce(GeoHashCellFacetResult other) { | ||
|
||
Map<String, ResultWithGroupings> countsCopy = Maps.newHashMap(this.counts); | ||
|
||
for (Map.Entry<String, ResultWithGroupings> pair : other.counts.entrySet()) { | ||
String key = pair.getKey(); | ||
ResultWithGroupings value = pair.getValue(); | ||
|
||
if (countsCopy.containsKey(key)) { | ||
ResultWithGroupings oldValue = countsCopy.get(key); | ||
countsCopy.remove(key); | ||
countsCopy.put(key, oldValue.merge(value)); | ||
} | ||
else { | ||
countsCopy.put(key, value); | ||
} | ||
} | ||
|
||
return new GeoHashCellFacetResult(countsCopy); | ||
} | ||
|
||
public static GeoHashCellFacetResult createFromEntryCounts(Map<GeoHashCellFacetEntry, AtomicLong> counts) { | ||
GeoHashCellFacetResult result = new GeoHashCellFacetResult(); | ||
|
||
for (Map.Entry<GeoHashCellFacetEntry, AtomicLong> entry : counts.entrySet()) { | ||
result = result.reduce(new GeoHashCellFacetResult(entry.getKey(), entry.getValue())); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public void toXContent(XContentBuilder builder) throws IOException { | ||
for (Map.Entry<String, ResultWithGroupings> entry : counts.entrySet()) { | ||
entry.getValue().toXContent(builder); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.