This project has retired. For details please refer to its Attic page.
SearchResults xref
View Javadoc
1   package org.apache.archiva.indexer.search;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  
28  /**
29   * SearchResults
30   *
31   */
32  public class SearchResults
33  {
34      private Map<String, SearchResultHit> hits = new HashMap<>();
35  
36      private int totalHits;
37  
38      private int totalHitsMapSize;
39  
40      private int returnedHitsCount;
41  
42      private SearchResultLimits limits;
43  
44      public SearchResults()
45      {
46          /* do nothing */
47      }
48  
49      // for new RepositorySearch
50      public void addHit( String id, SearchResultHit hit )
51      {
52          hits.put( id, hit );
53      }
54  
55      /**
56       * Get the list of {@link SearchResultHit} objects.
57       *
58       * @return the list of {@link SearchResultHit} objects.
59       */
60      public List<SearchResultHit> getHits()
61      {
62          return new ArrayList<>( hits.values() );
63      }
64  
65      /**
66       * see SearchUtil on how to generate the key
67       *
68       * @param key
69       * @return
70       */
71      public SearchResultHit getSearchResultHit( String key )
72      {
73          return hits.get( key );
74      }
75  
76      public Map<String, SearchResultHit> getHitsMap()
77      {
78          return hits;
79      }
80  
81      public boolean isEmpty()
82      {
83          return hits.isEmpty();
84      }
85  
86      public SearchResultLimits getLimits()
87      {
88          return limits;
89      }
90  
91      public void setLimits( SearchResultLimits limits )
92      {
93          this.limits = limits;
94      }
95  
96      public int getTotalHits()
97      {
98          return totalHits;
99      }
100 
101     public void setTotalHits( int totalHits )
102     {
103         this.totalHits = totalHits;
104     }
105 
106     /**
107      * @return
108      * @since 1.4-M1
109      */
110     public int getReturnedHitsCount()
111     {
112         return returnedHitsCount;
113     }
114 
115     /**
116      * @param returnedHitsCount
117      * @since 1.4-M1
118      */
119     public void setReturnedHitsCount( int returnedHitsCount )
120     {
121         this.returnedHitsCount = returnedHitsCount;
122     }
123 
124     /**
125      * @return
126      * @since 1.4-M1
127      */
128     public int getTotalHitsMapSize()
129     {
130         return totalHitsMapSize;
131     }
132 
133     /**
134      * @param totalHitsMapSize
135      * @since 1.4-M1
136      */
137     public void setTotalHitsMapSize( int totalHitsMapSize )
138     {
139         this.totalHitsMapSize = totalHitsMapSize;
140     }
141 
142     @Override
143     public String toString()
144     {
145         return "SearchResults{" + "hits=" + hits + ", totalHits=" + totalHits + ", returnedHitsCount="
146             + returnedHitsCount + ", limits=" + limits + '}';
147     }
148 }