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 public int getTotalHits() { 52 return getTotalHitsCount(); 53 } 54 55 /** 56 * Returns the number of total hits found by this query (total number of potential hits as reported by Lucene 57 * index). This is the number of existing AIs matching your query, and does not represent the count of hits 58 * delivered, which is returned by {@link #getReturnedHitsCount()}. 59 * 60 * @return 61 */ 62 public int getTotalHitsCount() { 63 return totalHitsCount; 64 } 65 66 /** 67 * Returns the number of hits returned by this search response. This number is affected by various input parameters 68 * (like count set on request) and filtering, paging, etc. Warning: this number's meaning depends on actual search 69 * response (for flat response number of actual AIs, for grouped response number of actual groups), and also, might 70 * be not precise at all (see {@link IteratorSearchResponse}). 71 * 72 * @return 73 */ 74 public int getReturnedHitsCount() { 75 return returnedHitsCount; 76 } 77 78 /** 79 * Returns true if hit limit exceeded. 80 * 81 * @return 82 * @deprecated always returns false, since 4.1.0 there is no notion of hit limit 83 * @see http://jira.codehaus.org/browse/MINDEXER-14 84 */ 85 public boolean isHitLimitExceeded() { 86 return false; 87 } 88 89 /** 90 * Frees any resource associated with this response. Should be called as last method on this response, when it's not 91 * used anymore. 92 * 93 * @throws IOException 94 */ 95 public void close() throws IOException { 96 // noop 97 } 98 }