1 package org.apache.lucene.search;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.util.concurrent.ExecutorService;
21 import java.io.IOException;
23 import org.apache.lucene.index.IndexReader;
26 * Helper class that adds some extra checks to ensure correct
27 * usage of {@code IndexSearcher} and {@code Weight}.
28 * TODO: Extend this by more checks, that's just a start.
30 public class AssertingIndexSearcher extends IndexSearcher {
31 public AssertingIndexSearcher(IndexReader r) {
35 public AssertingIndexSearcher(IndexReader r, ExecutorService ex) {
39 // not anonymous because else not serializable (compare trunk)
40 private static final class UnmodifiableWeight extends Weight {
41 private final Weight w;
43 UnmodifiableWeight(Weight w) {
48 public Explanation explain(IndexReader reader, int doc) throws IOException {
49 return w.explain(reader, doc);
53 public Query getQuery() {
58 public float getValue() {
63 public void normalize(float norm) {
64 throw new IllegalStateException("Weight already normalized.");
68 public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException {
69 return w.scorer(reader, scoreDocsInOrder, topScorer);
73 public float sumOfSquaredWeights() throws IOException {
74 throw new IllegalStateException("Weight already normalized.");
78 public boolean scoresDocsOutOfOrder() {
79 return w.scoresDocsOutOfOrder();
83 /** Ensures, that the returned {@code Weight} is not normalized again, which may produce wrong scores. */
85 public Weight createNormalizedWeight(Query query) throws IOException {
86 final Weight w = super.createNormalizedWeight(query);
87 return new UnmodifiableWeight(w);