/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.lucene.search;


import java.io.IOException;

import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.similarities.BM25Similarity;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase;

/** Document boost unit test.
 *
 *
 */
public class TestDocBoost extends LuceneTestCase {

  public void testDocBoost() throws Exception {
    Directory store = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random(), store, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));

    Field f1 = newTextField("field", "word", Field.Store.YES);
    Field f2 = newTextField("field", "word", Field.Store.YES);
    f2.setBoost(2.0f);

    Document d1 = new Document();
    Document d2 = new Document();

    d1.add(f1);                                 // boost = 1
    d2.add(f2);                                 // boost = 2

    writer.addDocument(d1);
    writer.addDocument(d2);

    IndexReader reader = writer.getReader();
    writer.close();

    final float[] scores = new float[4];

    IndexSearcher searcher = newSearcher(reader);
    searcher.setSimilarity(new BM25Similarity());
    searcher.search
      (new TermQuery(new Term("field", "word")),
       new SimpleCollector() {
         private int base = 0;
         private Scorer scorer;
         @Override
         public void setScorer(Scorer scorer) {
          this.scorer = scorer;
         }
         @Override
         public final void collect(int doc) throws IOException {
           scores[doc + base] = scorer.score();
         }
         @Override
         protected void doSetNextReader(LeafReaderContext context) throws IOException {
           base = context.docBase;
         }
         @Override
         public boolean needsScores() {
           return true;
         }
       });

    float lastScore = 0.0f;

    for (int i = 0; i < 2; i++) {
      if (VERBOSE) {
        System.out.println(searcher.explain(new TermQuery(new Term("field", "word")), i));
      }
      if (scores[i] != 0.0) {
        assertTrue("score: " + scores[i] + " should be > lastScore: " + lastScore, scores[i] > lastScore);
      }
      lastScore = scores[i];
    }
    
    reader.close();
    store.close();
  }
}

@@ -976,27 +976,33 @@
 e.index.
-Index
+Leaf
 Reader
+Context
 ;%0Aimport
@@ -1026,33 +1026,27 @@
 e.index.
-Leaf
+Index
 Reader
-Context
 ;%0Aimport
@@ -1130,69 +1130,8 @@
 rm;%0A
-import org.apache.lucene.search.similarities.BM25Similarity;%0A
 impo
@@ -2112,58 +2112,8 @@
 r);%0A
-    searcher.setSimilarity(new BM25Similarity());%0A
     

Revert the last change so we continue using randomize similarity for this test.