painless: _score as double, not float

This commit is contained in:
Robert Muir 2016-05-11 11:19:18 -04:00
parent 866a5459f0
commit d790c76636
2 changed files with 6 additions and 5 deletions

View File

@ -108,8 +108,8 @@ class Analyzer extends PainlessParserBaseVisitor<Void> {
// //
// loop counter to catch runaway scripts. internal use only. // loop counter to catch runaway scripts. internal use only.
metadata.loopCounterSlot = utility.addVariable(null, "#loop", definition.intType).slot; metadata.loopCounterSlot = utility.addVariable(null, "#loop", definition.intType).slot;
// document's score as a read-only float. // document's score as a read-only double.
metadata.scoreValueSlot = utility.addVariable(null, "_score", definition.floatType).slot; metadata.scoreValueSlot = utility.addVariable(null, "_score", definition.doubleType).slot;
// ctx map set by executable scripts as a read-only map. // ctx map set by executable scripts as a read-only map.
metadata.ctxValueSlot = utility.addVariable(null, "ctx", definition.smapType).slot; metadata.ctxValueSlot = utility.addVariable(null, "ctx", definition.smapType).slot;

View File

@ -152,15 +152,16 @@ class Writer extends PainlessParserBaseVisitor<Void> {
private void writeExecute() { private void writeExecute() {
if (metadata.scoreValueUsed) { if (metadata.scoreValueUsed) {
// if the _score value is used, we do this once: // if the _score value is used, we do this once:
// float _score = scorer.score(); // final double _score = scorer.score();
execute.visitVarInsn(Opcodes.ALOAD, metadata.scorerValueSlot); execute.visitVarInsn(Opcodes.ALOAD, metadata.scorerValueSlot);
execute.invokeVirtual(WriterConstants.SCORER_TYPE, WriterConstants.SCORER_SCORE); execute.invokeVirtual(WriterConstants.SCORER_TYPE, WriterConstants.SCORER_SCORE);
execute.visitVarInsn(Opcodes.FSTORE, metadata.scoreValueSlot); execute.visitInsn(Opcodes.F2D);
execute.visitVarInsn(Opcodes.DSTORE, metadata.scoreValueSlot);
} }
if (metadata.ctxValueUsed) { if (metadata.ctxValueUsed) {
// if the _ctx value is used, we do this once: // if the _ctx value is used, we do this once:
// Map<String,Object> ctx = input.get("ctx"); // final Map<String,Object> ctx = input.get("ctx");
execute.visitVarInsn(Opcodes.ALOAD, metadata.inputValueSlot); execute.visitVarInsn(Opcodes.ALOAD, metadata.inputValueSlot);
execute.push("ctx"); execute.push("ctx");
execute.invokeInterface(WriterConstants.MAP_TYPE, WriterConstants.MAP_GET); execute.invokeInterface(WriterConstants.MAP_TYPE, WriterConstants.MAP_GET);