Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Added support for "search_after" in elasticsearch queries #3230

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import java.util.ArrayList;
/**
* A graph query that runs directly against a particular index.
*
Expand Down Expand Up @@ -103,7 +103,7 @@ interface Result<V, E> {
DirectIndexQueryResult<V, E> getCollapseVertices(String key);

Map<String, List<String>> getHighLights();

ArrayList<Object> getSort();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ public DirectIndexQueryResult<AtlasJanusVertex, AtlasJanusEdge> getCollapseVerti
public Map<String, List<String>> getHighLights() {
return new HashMap<>();
}

@Override
public ArrayList<Object> getSort() {
return new ArrayList<>();
}
}


Expand Down Expand Up @@ -609,6 +614,15 @@ public Map<String, List<String>> getHighLights() {
}
return new HashMap<>();
}

@Override
public ArrayList<Object> getSort() {
Object sort = this.hit.get("sort");
if (Objects.nonNull(sort) && sort instanceof List) {
return (ArrayList<Object>) sort;
}
return new ArrayList<>();
}
}

public class AsyncQueryResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,10 @@ public DirectIndexQueryResult<AtlasJanusVertex, AtlasJanusEdge> getCollapseVerti
public Map<String, List<String>> getHighLights() {
return new HashMap<>();
}

@Override
public ArrayList<Object> getSort() {
return new ArrayList<>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.LinkedHashMap;

import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
Expand All @@ -59,7 +60,7 @@ public class AtlasSearchResult implements Serializable {
private Map<String, Object> aggregations;
private Map<String,Double> searchScore;

private Map<String, ElasticsearchMetadata> searchMetadata;
private LinkedHashMap<String, ElasticsearchMetadata> searchMetadata;



Expand Down Expand Up @@ -162,13 +163,26 @@ public Map<String, ElasticsearchMetadata> getSearchMetadata() {

public void addHighlights(String guid, Map<String, List<String>> highlights) {
if(MapUtils.isEmpty(this.searchMetadata)) {
this.searchMetadata = new HashMap<>();
this.searchMetadata = new LinkedHashMap<>();
}
ElasticsearchMetadata v = this.searchMetadata.getOrDefault(guid, new ElasticsearchMetadata());
v.addHighlights(highlights);
this.searchMetadata.put(guid, v);
}

public void addSort(String guid, ArrayList sort) {
if(MapUtils.isEmpty(this.searchMetadata)) {
this.searchMetadata = new LinkedHashMap<>();
}
ElasticsearchMetadata v = this.searchMetadata.getOrDefault(guid, new ElasticsearchMetadata());
v.addSort(sort);
if (this.searchMetadata.containsKey(guid)) {
this.searchMetadata.replace(guid, v);
} else {
this.searchMetadata.put(guid, v);
}
}

@Override
public int hashCode() { return Objects.hash(queryType, searchParameters, queryText, type, classification, entities, attributes, fullTextResult, referredEntities, nextMarker); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;

public class ElasticsearchMetadata {

private Map<String, List<String>> highlights;
private ArrayList<Object> sort;

public Map<String, List<String>> getHighlights() {
return highlights;
Expand All @@ -23,6 +25,17 @@ public void addHighlights(Map<String, List<String>> highlights) {
}
}

public Object getSort() { return sort; }

public void addSort(ArrayList<Object> sort) {

if(!sort.isEmpty()) {
if (MapUtils.isEmpty(this.highlights)) {
this.sort = new ArrayList<>();
}
this.sort = sort;
}
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ private void prepareSearchResult(AtlasSearchResult ret, DirectIndexQueryResult i

if (searchParams.isShowHighlights()) {
ret.addHighlights(header.getGuid(), result.getHighLights());
ret.addSort(header.getGuid(), result.getSort());
}

ret.addEntity(header);
Expand Down
Loading