pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / java / org / apache / lucene / search / ComplexExplanation.java
1 package org.apache.lucene.search;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 /** Expert: Describes the score computation for document and query, and
21  * can distinguish a match independent of a positive value. */
22 public class ComplexExplanation extends Explanation {
23   private Boolean match;
24   
25   public ComplexExplanation() {
26     super();
27   }
28
29   public ComplexExplanation(boolean match, float value, String description) {
30     // NOTE: use of "boolean" instead of "Boolean" in params is conscious
31     // choice to encourage clients to be specific.
32     super(value, description);
33     this.match = Boolean.valueOf(match);
34   }
35
36   /**
37    * The match status of this explanation node.
38    * @return May be null if match status is unknown
39    */
40   public Boolean getMatch() { return match; }
41   /**
42    * Sets the match status assigned to this explanation node.
43    * @param match May be null if match status is unknown
44    */
45   public void setMatch(Boolean match) { this.match = match; }
46   /**
47    * Indicates whether or not this Explanation models a good match.
48    *
49    * <p>
50    * If the match status is explicitly set (i.e.: not null) this method
51    * uses it; otherwise it defers to the superclass.
52    * </p>
53    * @see #getMatch
54    */
55   @Override
56   public boolean isMatch() {
57     Boolean m = getMatch();
58     return (null != m ? m.booleanValue() : super.isMatch());
59   }
60
61   @Override
62   protected String getSummary() {
63     if (null == getMatch())
64       return super.getSummary();
65     
66     return getValue() + " = "
67       + (isMatch() ? "(MATCH) " : "(NON-MATCH) ")
68       + getDescription();
69   }
70   
71 }