View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.index;
20  
21  import java.io.Closeable;
22  import java.io.IOException;
23  
24  import org.apache.lucene.search.Query;
25  
26  public class AbstractSearchResponse implements Closeable {
27      private final Query query;
28  
29      private final int totalHitsCount;
30  
31      private final int returnedHitsCount;
32  
33      public AbstractSearchResponse(final Query query, final int totalHitsCount, final int returnedHitsCount) {
34          this.query = query;
35  
36          this.totalHitsCount = totalHitsCount;
37  
38          this.returnedHitsCount = returnedHitsCount;
39      }
40  
41      public Query getQuery() {
42          return query;
43      }
44  
45      /**
46       * Returns the number of total hits found. This may be different that actual hits returned (is usually more).
47       *
48       * @return
49       * @deprecated use {@link #getTotalHitsCount()} instead.
50       */
51      @Deprecated
52      public int getTotalHits() {
53          return getTotalHitsCount();
54      }
55  
56      /**
57       * Returns the number of total hits found by this query (total number of potential hits as reported by Lucene
58       * index). This is the number of existing AIs matching your query, and does not represent the count of hits
59       * delivered, which is returned by {@link #getReturnedHitsCount()}.
60       *
61       * @return
62       */
63      public int getTotalHitsCount() {
64          return totalHitsCount;
65      }
66  
67      /**
68       * Returns the number of hits returned by this search response. This number is affected by various input parameters
69       * (like count set on request) and filtering, paging, etc. Warning: this number's meaning depends on actual search
70       * response (for flat response number of actual AIs, for grouped response number of actual groups), and also, might
71       * be not precise at all (see {@link IteratorSearchResponse}).
72       *
73       * @return
74       */
75      public int getReturnedHitsCount() {
76          return returnedHitsCount;
77      }
78  
79      /**
80       * Returns true if hit limit exceeded.
81       *
82       * @return
83       * @deprecated always returns false, since 4.1.0 there is no notion of hit limit
84       * @see http://jira.codehaus.org/browse/MINDEXER-14
85       */
86      @Deprecated
87      public boolean isHitLimitExceeded() {
88          return false;
89      }
90  
91      /**
92       * Frees any resource associated with this response. Should be called as last method on this response, when it's not
93       * used anymore.
94       *
95       * @throws IOException
96       */
97      public void close() throws IOException {
98          // noop
99      }
100 }