Skip to content

Commit 27cc937

Browse files
authored
Merge pull request #846 from lonvia/improve-debug-output
opensearch: dump raw result data on debug
2 parents daae537 + bc251d5 commit 27cc937

File tree

7 files changed

+42
-9
lines changed

7 files changed

+42
-9
lines changed

app/es_embedded/src/main/java/de/komoot/photon/elasticsearch/ElasticResult.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import de.komoot.photon.searcher.PhotonResult;
55
import org.elasticsearch.search.SearchHit;
66
import org.slf4j.Logger;
7+
import org.json.JSONObject;
78

89
import java.util.List;
910
import java.util.Map;
@@ -83,4 +84,9 @@ public double[] getExtent() {
8384
public double getScore() {
8485
return result.getScore();
8586
}
87+
88+
@Override
89+
public JSONObject getRawData() {
90+
return new JSONObject();
91+
}
8692
}

app/es_embedded/src/test/java/de/komoot/photon/elasticsearch/ElasticGetIdResult.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import de.komoot.photon.searcher.PhotonResult;
44
import org.apache.commons.lang3.NotImplementedException;
55
import org.elasticsearch.action.get.GetResponse;
6+
import org.json.JSONObject;
67

78
import java.util.Map;
89

@@ -42,4 +43,9 @@ public double[] getExtent() {
4243
public double getScore() {
4344
throw new NotImplementedException();
4445
}
46+
47+
@Override
48+
public JSONObject getRawData() {
49+
throw new NotImplementedException();
50+
}
4551
}

app/opensearch/src/main/java/de/komoot/photon/opensearch/OpenSearchResult.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package de.komoot.photon.opensearch;
22

33
import de.komoot.photon.searcher.PhotonResult;
4+
import jakarta.json.JsonArray;
5+
import org.json.JSONObject;
46

57
import java.util.Map;
68

@@ -69,4 +71,12 @@ public double[] getExtent() {
6971
public double getScore() {
7072
return score;
7173
}
74+
75+
@Override
76+
public JSONObject getRawData() {
77+
return new JSONObject()
78+
.put("infos", new JSONObject(infos))
79+
.put("localeTags", new JSONObject(localeTags))
80+
.put("score", score);
81+
}
7282
}

app/opensearch/src/main/java/de/komoot/photon/opensearch/OpenSearchSearchHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public List<PhotonResult> search(PhotonRequest request) {
4444

4545
@Override
4646
public String dumpQuery(PhotonRequest photonRequest) {
47-
return "{}";
47+
return null;
4848
}
4949

5050
private SearchQueryBuilder buildQuery(PhotonRequest request, boolean lenient) {

src/main/java/de/komoot/photon/searcher/GeocodeJsonFormatter.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ public String convert(List<PhotonResult> results, String debugInfo) {
4040
out.put("type", "FeatureCollection")
4141
.put("features", features);
4242

43-
if (debugInfo != null) {
44-
out.put("properties", new JSONObject().put("debug", new JSONObject(debugInfo)));
45-
}
46-
4743
if (addDebugInfo) {
44+
final JSONObject extraProps = new JSONObject();
45+
if (debugInfo != null) {
46+
extraProps.put("debug", new JSONObject(debugInfo));
47+
}
48+
final JSONArray rawResults = new JSONArray();
49+
results.forEach(res -> rawResults.put(res.getRawData()));
50+
extraProps.put("raw_data", rawResults);
51+
out.put("properties", extraProps);
52+
4853
return out.toString(4);
4954
}
5055

@@ -53,10 +58,6 @@ public String convert(List<PhotonResult> results, String debugInfo) {
5358

5459
private JSONObject getResultProperties(PhotonResult result) {
5560
JSONObject props = new JSONObject();
56-
if (addDebugInfo) {
57-
props.put("score", result.getScore());
58-
put(props,"importance", result.get("importance"));
59-
}
6061

6162
for (String key : KEYS_LANG_UNSPEC) {
6263
put(props, key, result.get(key));

src/main/java/de/komoot/photon/searcher/PhotonResult.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.komoot.photon.searcher;
22

3+
import org.json.JSONObject;
4+
35
import java.util.Map;
46

57
/**
@@ -26,4 +28,5 @@ public interface PhotonResult {
2628

2729
double getScore();
2830

31+
JSONObject getRawData();
2932
}

src/test/java/de/komoot/photon/searcher/MockPhotonResult.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.komoot.photon.searcher;
22

3+
import org.json.JSONObject;
4+
35
import java.util.HashMap;
46
import java.util.Map;
57

@@ -49,4 +51,9 @@ public MockPhotonResult putLocalized(String key, String lang, String value) {
4951
localized.put(key + "||" + lang, value);
5052
return this;
5153
}
54+
55+
@Override
56+
public JSONObject getRawData() {
57+
return new JSONObject();
58+
}
5259
}

0 commit comments

Comments
 (0)