aboutsummaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahooinc.com>2022-01-24 08:12:50 +0000
committerArne H Juul <arnej@yahooinc.com>2022-01-24 08:12:50 +0000
commit6a7fbb1dc9b77bb9ebbbc8083ccd426bf0be8624 (patch)
treeab75a72255b914d7598951dcc551cfdec5a8121c /container-search
parent09e000c9cde9943232098f02aec7f51961686860 (diff)
refactor
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java53
1 files changed, 25 insertions, 28 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java
index 157223c110c..9009fb227da 100644
--- a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java
+++ b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java
@@ -134,6 +134,29 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> {
boolean jsonWsetsAll = false;
boolean tensorShortForm = false;
boolean convertDeep() { return (jsonDeepMaps || jsonWsets); }
+ void init() {
+ this.debugRendering = false;
+ this.jsonDeepMaps = false;
+ this.jsonWsets = false;
+ this.jsonMapsAll = false;
+ this.jsonWsetsAll = false;
+ this.tensorShortForm = false;
+ }
+ void getSettings(Query q) {
+ if (q == null) {
+ init();
+ return;
+ }
+ var props = q.properties();
+ this.debugRendering = props.getBoolean(DEBUG_RENDERING_KEY, false);
+ this.jsonDeepMaps = props.getBoolean(WRAP_DEEP_MAPS, false);
+ this.jsonWsets = props.getBoolean(WRAP_WSETS, false);
+ // we may need more fine tuning, but for now use the same query parameters here:
+ this.jsonMapsAll = props.getBoolean(WRAP_DEEP_MAPS, false);
+ this.jsonWsetsAll = props.getBoolean(WRAP_WSETS, false);
+ this.tensorShortForm = (props.get(TENSOR_FORMAT) != null &&
+ props.getString(TENSOR_FORMAT).equalsIgnoreCase("short"));
+ }
}
private final FieldConsumerSettings fieldConsumerSettings = new FieldConsumerSettings();
private LongSupplier timeSource;
@@ -167,12 +190,7 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> {
@Override
public void init() {
super.init();
- fieldConsumerSettings.debugRendering = false;
- fieldConsumerSettings.jsonDeepMaps = false;
- fieldConsumerSettings.jsonWsets = false;
- fieldConsumerSettings.jsonMapsAll = false;
- fieldConsumerSettings.jsonWsetsAll = false;
- fieldConsumerSettings.tensorShortForm = false;
+ fieldConsumerSettings.init();
setGenerator(null, fieldConsumerSettings);
renderedChildren = null;
timeSource = System::currentTimeMillis;
@@ -182,7 +200,7 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> {
@Override
public void beginResponse(OutputStream stream) throws IOException {
beginJsonCallback(stream);
- getSettings(getResult().getQuery());
+ fieldConsumerSettings.getSettings(getResult().getQuery());
setGenerator(generatorFactory.createGenerator(stream, JsonEncoding.UTF8), fieldConsumerSettings);
renderedChildren = new ArrayDeque<>();
generator.writeStartObject();
@@ -213,27 +231,6 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> {
generator.writeEndObject();
}
- private void getSettings(Query q) {
- if (q == null) {
- fieldConsumerSettings.debugRendering = false;
- fieldConsumerSettings.jsonDeepMaps = false;
- fieldConsumerSettings.jsonWsets = false;
- fieldConsumerSettings.jsonMapsAll = false;
- fieldConsumerSettings.jsonWsetsAll = false;
- fieldConsumerSettings.tensorShortForm = false;
- return;
- }
- var props = q.properties();
- fieldConsumerSettings.debugRendering = props.getBoolean(DEBUG_RENDERING_KEY, false);
- fieldConsumerSettings.jsonDeepMaps = props.getBoolean(WRAP_DEEP_MAPS, false);
- fieldConsumerSettings.jsonWsets = props.getBoolean(WRAP_WSETS, false);
- // we may need more fine tuning, but for now use the same query parameters here:
- fieldConsumerSettings.jsonMapsAll = props.getBoolean(WRAP_DEEP_MAPS, false);
- fieldConsumerSettings.jsonWsetsAll = props.getBoolean(WRAP_WSETS, false);
- fieldConsumerSettings.tensorShortForm = (props.get(TENSOR_FORMAT) != null &&
- props.getString(TENSOR_FORMAT).equalsIgnoreCase("short"));
- }
-
protected void renderTrace(Trace trace) throws IOException {
if (!trace.traceNode().children().iterator().hasNext()) return;
if (getResult().getQuery().getTraceLevel() == 0) return;