apache / apache/lucene

FunctionQuery.AllScorer.explain overwrites FunctionWeight.queryNorm in trappy fashion [LUCENE-6806]

Open
#7,864 0 comments 0 reactions 0 assignees View on GitHub
affects-version:6.0 legacy-jira-priority:Minor type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

FunctionQuery.AllScorer.explain is:

```java
public Explanation explain(int doc, float queryNorm) throws IOException {
float sc = qWeight * vals.floatVal(doc);

return Explanation.match(sc, "FunctionQuery(" + func + "), product of:",
vals.explain(doc),
Explanation.match(queryNorm, "boost"),
Explanation.match(weight.queryNorm = 1f, "queryNorm"));
}
```

The following line has a subtle assignment that overwrites weight.queryNorm.

```java
Explanation.match(weight.queryNorm = 1f, "queryNorm"));
```

Because weights aren't reused between search and explain this doesn't break anything but it's awfully subtle.

Seeing as queryNorm is ALWAYS 1 here, could we just drop this extra line from the explain output and use the following instead?

```java
public Explanation explain(int doc, float queryNorm) throws IOException {
float sc = qWeight * vals.floatVal(doc);

return Explanation.match(sc, "FunctionQuery(" + func + "), product of:",
vals.explain(doc),
Explanation.match(queryNorm, "boost"));
}
```

---
Migrated from [LUCENE-6806](https://issues.apache.org/jira/browse/LUCENE-6806) by Terry Smith, updated May 09 2016
Linked issues:
- #8264

Contributor guide

Open the contributing guide

Research direction

Start at FunctionQuery.AllScorer.explain and inspect how its Explanation entries represent queryNorm. Remove the subtle assignment from the explanation as proposed, then verify that the output no longer includes that entry and that the existing Lucene tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.