From 876c7e04006750584f88c50305cf2ccc37523a2b Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 27 Jul 2017 11:17:56 +0200 Subject: [PATCH] Fix random score generation when no seed is provided. (#25908) It fixes random score generation to ensure that you will not always get the same scores on a read-only index by integrating the seed into the score computation when using doc ids. It also removes `ctx.docBase` from the formula since it might change over time if deletes are compacted while scores are supposed to be cacheable per segment. --- .../common/lucene/search/function/RandomScoreFunction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/function/RandomScoreFunction.java b/core/src/main/java/org/elasticsearch/common/lucene/search/function/RandomScoreFunction.java index 601363a9384..a104a416cc6 100644 --- a/core/src/main/java/org/elasticsearch/common/lucene/search/function/RandomScoreFunction.java +++ b/core/src/main/java/org/elasticsearch/common/lucene/search/function/RandomScoreFunction.java @@ -70,7 +70,7 @@ public class RandomScoreFunction extends ScoreFunction { public double score(int docId, float subQueryScore) throws IOException { int hash; if (values == null) { - hash = BitMixer.mix(ctx.docBase + docId); + hash = BitMixer.mix(docId, saltedSeed); } else if (values.advanceExact(docId)) { hash = StringHelper.murmurhash3_x86_32(values.nextValue(), saltedSeed); } else {