Skip to content

Commit

Permalink
ngageoint#91 Implemented support for highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
dclemenzi committed Nov 28, 2018
1 parent 9103f88 commit 5f38410
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private String nextHit() {
final ElasticHit hit = searchHitIterator.next();
final SimpleFeatureType type = getFeatureType();
final Map<String, Object> source = hit.getSource();
final Map<String, List<String>> highlights = hit.getHighlight();

final Float score;
final Float relativeScore;
Expand All @@ -120,6 +121,12 @@ private String nextHit() {
final String sourceName = (String) descriptor.getUserData().get(FULL_NAME);

List<Object> values = hit.field(sourceName);

if (values == null && highlights != null && highlights.containsKey(sourceName)) {
// read field from source
values = Collections.unmodifiableList(highlights.get(sourceName));
}

if (values == null && source != null) {
// read field from source
values = parserUtil.readField(source, sourceName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
Expand Down Expand Up @@ -218,6 +219,18 @@ private ElasticRequest prepareSearchRequest(Query query, boolean scroll) throws
searchRequest.setSize(0);
}

if (filterToElastic.gethighlights() != null) {
searchRequest.setHighlights(filterToElastic.gethighlights());

List<String> source = searchRequest.getSourceIncludes();
for (String key : filterToElastic.gethighlights().keySet()) {
if (source.contains(key))
{
source.remove(key);
}
}
}

return searchRequest;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ElasticHit {

private Map<String,List<Object>> fields;

private Map<String,List<String>> highlight;

public String getIndex() {
return index;
}
Expand Down Expand Up @@ -78,4 +80,11 @@ public List<Object> field(String name) {
return this.fields != null ? this.fields.get(name) : null;
}

public Map<String, List<String>> getHighlight() {
return highlight;
}

public void setHighlight(Map<String, List<String>> highlight) {
this.highlight = highlight;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class ElasticRequest {

private Map<String,Map<String,Map<String,Object>>> aggregations;

private Map<String, Object> highlights;

private Integer size;

private Integer from;
Expand Down Expand Up @@ -49,6 +51,14 @@ public void setAggregations(Map<String,Map<String,Map<String,Object>>> aggregati
this.aggregations = aggregations;
}

public Map<String, Object> getHighlights() {
return highlights;
}

public void setHighlights(Map<String, Object> highlights) {
this.highlights = highlights;
}

public Integer getSize() {
return size;
}
Expand Down
Loading

0 comments on commit 5f38410

Please sign in to comment.