mirror of https://github.com/apache/lucene.git
fix tf + termfreq functions when no terms in field
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1138732 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
635934f150
commit
0333b8caf0
|
@ -53,7 +53,7 @@ public class TFValueSource extends TermFreqValueSource {
|
|||
|
||||
public void reset() throws IOException {
|
||||
// no one should call us for deleted docs?
|
||||
docs = terms.docs(null, indexedBytes, null);
|
||||
docs = terms==null ? null : terms.docs(null, indexedBytes, null);
|
||||
if (docs == null) {
|
||||
docs = new DocsEnum() {
|
||||
@Override
|
||||
|
|
|
@ -50,7 +50,7 @@ public class TermFreqValueSource extends DocFreqValueSource {
|
|||
|
||||
public void reset() throws IOException {
|
||||
// no one should call us for deleted docs?
|
||||
docs = terms.docs(null, indexedBytes, null);
|
||||
docs = terms == null ? null : terms.docs(null, indexedBytes, null);
|
||||
if (docs == null) {
|
||||
docs = new DocsEnum() {
|
||||
@Override
|
||||
|
|
|
@ -289,7 +289,17 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
|
|||
assertQ(req("fl","*,score","q", "{!func}docfreq('a_t','cow')", "fq","id:6"), "//float[@name='score']='3.0'");
|
||||
assertQ(req("fl","*,score","q", "{!func}docfreq($field,$value)", "fq","id:6", "field","a_t", "value","cow"), "//float[@name='score']='3.0'");
|
||||
assertQ(req("fl","*,score","q", "{!func}termfreq(a_t,cow)", "fq","id:6"), "//float[@name='score']='5.0'");
|
||||
|
||||
Similarity similarity = new DefaultSimilarity();
|
||||
|
||||
// make sure it doesn't get a NPE if no terms are present in a field.
|
||||
assertQ(req("fl","*,score","q", "{!func}termfreq(nofield_t,cow)", "fq","id:6"), "//float[@name='score']='0.0'");
|
||||
assertQ(req("fl","*,score","q", "{!func}docfreq(nofield_t,cow)", "fq","id:6"), "//float[@name='score']='0.0'");
|
||||
assertQ(req("fl","*,score","q", "{!func}idf(nofield_t,cow)", "fq","id:6"),
|
||||
"//float[@name='score']='" + similarity.idf(0,6) + "'");
|
||||
assertQ(req("fl","*,score","q", "{!func}tf(nofield_t,cow)", "fq","id:6"),
|
||||
"//float[@name='score']='" + similarity.tf(0) + "'");
|
||||
|
||||
assertQ(req("fl","*,score","q", "{!func}idf(a_t,cow)", "fq","id:6"),
|
||||
"//float[@name='score']='" + similarity.idf(3,6) + "'");
|
||||
assertQ(req("fl","*,score","q", "{!func}tf(a_t,cow)", "fq","id:6"),
|
||||
|
|
Loading…
Reference in New Issue