LUCENE-8892: add missing closing parentheses in MultiBoolFunction's description()

This commit is contained in:
Munendra S N 2019-07-01 12:43:12 +05:30
parent 82bf95727e
commit dc16e2707b
3 changed files with 34 additions and 4 deletions

View File

@ -115,6 +115,8 @@ Bug Fixes
* LUCENE-8853: FileSwitchDirectory now applies best effort to place tmp files in the same
directory as the target files. (Simon Willnauer)
* LUCENE-8892: Add missing closing parentheses in MultiBoolFunction's description() (Florian Diebold, Munendra S N)
Improvements
* LUCENE-7840: Non-scoring BooleanQuery now removes SHOULD clauses before building the scorer supplier

View File

@ -16,16 +16,16 @@
*/
package org.apache.lucene.queries.function.valuesource;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.docvalues.BoolDocValues;
import org.apache.lucene.search.IndexSearcher;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* Abstract {@link ValueSource} implementation which wraps multiple ValueSources
* and applies an extendible boolean function to their values.
@ -68,6 +68,7 @@ public abstract class MultiBoolFunction extends BoolFunction {
}
sb.append(dv.toString(doc));
}
sb.append(')');
return sb.toString();
}
};
@ -86,6 +87,7 @@ public abstract class MultiBoolFunction extends BoolFunction {
}
sb.append(source.description());
}
sb.append(')');
return sb.toString();
}

View File

@ -17,6 +17,7 @@
package org.apache.lucene.queries.function;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -486,6 +487,31 @@ public class TestValueSources extends LuceneTestCase {
assertHits(new FunctionQuery(vs), new float[] { 0F, 0F });
assertAllExist(vs);
}
public void testMultiBoolFunction() throws Exception {
// verify toString and description
List<ValueSource> valueSources = new ArrayList<>(Arrays.asList(
new ConstValueSource(4.1f), new ConstValueSource(1.2f), new DoubleFieldSource("some_double")
));
ValueSource vs = new MultiBoolFunction(valueSources) {
@Override
protected String name() {
return "test";
}
@Override
protected boolean func(int doc, FunctionValues[] vals) throws IOException {
return false;
}
};
assertEquals("test(const(4.1),const(1.2),double(some_double))", vs.description());
final LeafReaderContext leaf = searcher.getIndexReader().leaves().get(0);
FunctionValues fv = vs.getValues(ValueSource.newContext(searcher), leaf);
// doesn't matter what is the docId, verify toString
assertEquals("test(const(4.1),const(1.2),double(some_double)=0.0)", fv.toString(1));
}
public void testTF() throws Exception {
Similarity saved = searcher.getSimilarity();