use searcher.createNormalizedWeight() instead of query.getWeight() and cleanup

This commit is contained in:
Britta Weber 2015-10-07 14:46:47 +02:00
parent 473d25beed
commit bb939f819c
1 changed files with 2 additions and 4 deletions

View File

@ -256,8 +256,6 @@ public class FunctionScoreTests extends ESTestCase {
public void initSearcher() throws IOException { public void initSearcher() throws IOException {
dir = newDirectory(); dir = newDirectory();
w = new IndexWriter(dir, newIndexWriterConfig(new StandardAnalyzer())); w = new IndexWriter(dir, newIndexWriterConfig(new StandardAnalyzer()));
FieldType ft = new FieldType(TextField.TYPE_STORED);
ft.freeze();
Document d = new Document(); Document d = new Document();
d.add(new TextField(FIELD, TEXT, Field.Store.YES)); d.add(new TextField(FIELD, TEXT, Field.Store.YES));
d.add(new TextField("_uid", "1", Field.Store.YES)); d.add(new TextField("_uid", "1", Field.Store.YES));
@ -310,7 +308,7 @@ public class FunctionScoreTests extends ESTestCase {
public Explanation getFunctionScoreExplanation(IndexSearcher searcher, ScoreFunction scoreFunction) throws IOException { public Explanation getFunctionScoreExplanation(IndexSearcher searcher, ScoreFunction scoreFunction) throws IOException {
FunctionScoreQuery functionScoreQuery = new FunctionScoreQuery(new TermQuery(TERM), scoreFunction, 0.0f, CombineFunction.AVG, 100); FunctionScoreQuery functionScoreQuery = new FunctionScoreQuery(new TermQuery(TERM), scoreFunction, 0.0f, CombineFunction.AVG, 100);
Weight weight = functionScoreQuery.createWeight(searcher, true); Weight weight = searcher.createNormalizedWeight(functionScoreQuery, true);
Explanation explanation = weight.explain(searcher.getIndexReader().leaves().get(0), 0); Explanation explanation = weight.explain(searcher.getIndexReader().leaves().get(0), 0);
return explanation.getDetails()[1]; return explanation.getDetails()[1];
} }
@ -375,7 +373,7 @@ public class FunctionScoreTests extends ESTestCase {
public Explanation getFiltersFunctionScoreExplanation(IndexSearcher searcher, ScoreFunction... scoreFunctions) throws IOException { public Explanation getFiltersFunctionScoreExplanation(IndexSearcher searcher, ScoreFunction... scoreFunctions) throws IOException {
FiltersFunctionScoreQuery filtersFunctionScoreQuery = getFiltersFunctionScoreQuery(FiltersFunctionScoreQuery.ScoreMode.AVG, CombineFunction.AVG, scoreFunctions); FiltersFunctionScoreQuery filtersFunctionScoreQuery = getFiltersFunctionScoreQuery(FiltersFunctionScoreQuery.ScoreMode.AVG, CombineFunction.AVG, scoreFunctions);
Weight weight = filtersFunctionScoreQuery.createWeight(searcher, true); Weight weight = searcher.createNormalizedWeight(filtersFunctionScoreQuery, true);
Explanation explanation = weight.explain(searcher.getIndexReader().leaves().get(0), 0); Explanation explanation = weight.explain(searcher.getIndexReader().leaves().get(0), 0);
return explanation.getDetails()[1]; return explanation.getDetails()[1];
} }