Skip to content

Commit

Permalink
Merge pull request #846 from lonvia/improve-debug-output
Browse files Browse the repository at this point in the history
opensearch: dump raw result data on debug
  • Loading branch information
lonvia authored Nov 12, 2024
2 parents daae537 + bc251d5 commit 27cc937
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.komoot.photon.searcher.PhotonResult;
import org.elasticsearch.search.SearchHit;
import org.slf4j.Logger;
import org.json.JSONObject;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -83,4 +84,9 @@ public double[] getExtent() {
public double getScore() {
return result.getScore();
}

@Override
public JSONObject getRawData() {
return new JSONObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.komoot.photon.searcher.PhotonResult;
import org.apache.commons.lang3.NotImplementedException;
import org.elasticsearch.action.get.GetResponse;
import org.json.JSONObject;

import java.util.Map;

Expand Down Expand Up @@ -42,4 +43,9 @@ public double[] getExtent() {
public double getScore() {
throw new NotImplementedException();
}

@Override
public JSONObject getRawData() {
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.komoot.photon.opensearch;

import de.komoot.photon.searcher.PhotonResult;
import jakarta.json.JsonArray;
import org.json.JSONObject;

import java.util.Map;

Expand Down Expand Up @@ -69,4 +71,12 @@ public double[] getExtent() {
public double getScore() {
return score;
}

@Override
public JSONObject getRawData() {
return new JSONObject()
.put("infos", new JSONObject(infos))
.put("localeTags", new JSONObject(localeTags))
.put("score", score);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<PhotonResult> search(PhotonRequest request) {

@Override
public String dumpQuery(PhotonRequest photonRequest) {
return "{}";
return null;
}

private SearchQueryBuilder buildQuery(PhotonRequest request, boolean lenient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ public String convert(List<PhotonResult> results, String debugInfo) {
out.put("type", "FeatureCollection")
.put("features", features);

if (debugInfo != null) {
out.put("properties", new JSONObject().put("debug", new JSONObject(debugInfo)));
}

if (addDebugInfo) {
final JSONObject extraProps = new JSONObject();
if (debugInfo != null) {
extraProps.put("debug", new JSONObject(debugInfo));
}
final JSONArray rawResults = new JSONArray();
results.forEach(res -> rawResults.put(res.getRawData()));
extraProps.put("raw_data", rawResults);
out.put("properties", extraProps);

return out.toString(4);
}

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

private JSONObject getResultProperties(PhotonResult result) {
JSONObject props = new JSONObject();
if (addDebugInfo) {
props.put("score", result.getScore());
put(props,"importance", result.get("importance"));
}

for (String key : KEYS_LANG_UNSPEC) {
put(props, key, result.get(key));
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/komoot/photon/searcher/PhotonResult.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.komoot.photon.searcher;

import org.json.JSONObject;

import java.util.Map;

/**
Expand All @@ -26,4 +28,5 @@ public interface PhotonResult {

double getScore();

JSONObject getRawData();
}
7 changes: 7 additions & 0 deletions src/test/java/de/komoot/photon/searcher/MockPhotonResult.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.komoot.photon.searcher;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -49,4 +51,9 @@ public MockPhotonResult putLocalized(String key, String lang, String value) {
localized.put(key + "||" + lang, value);
return this;
}

@Override
public JSONObject getRawData() {
return new JSONObject();
}
}

0 comments on commit 27cc937

Please sign in to comment.