001    package org.apache.archiva.indexer.search;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.ArrayList;
023    import java.util.HashMap;
024    import java.util.List;
025    import java.util.Map;
026    
027    
028    /**
029     * SearchResults
030     *
031     */
032    public class SearchResults
033    {
034        private Map<String, SearchResultHit> hits = new HashMap<String, SearchResultHit>();
035    
036        private int totalHits;
037    
038        private int totalHitsMapSize;
039    
040        private int returnedHitsCount;
041    
042        private SearchResultLimits limits;
043    
044        public SearchResults()
045        {
046            /* do nothing */
047        }
048    
049        // for new RepositorySearch
050        public void addHit( String id, SearchResultHit hit )
051        {
052            hits.put( id, hit );
053        }
054    
055        /**
056         * Get the list of {@link SearchResultHit} objects.
057         *
058         * @return the list of {@link SearchResultHit} objects.
059         */
060        public List<SearchResultHit> getHits()
061        {
062            return new ArrayList<SearchResultHit>( hits.values() );
063        }
064    
065        /**
066         * see SearchUtil on how to generate the key
067         *
068         * @param key
069         * @return
070         */
071        public SearchResultHit getSearchResultHit( String key )
072        {
073            return hits.get( key );
074        }
075    
076        public Map<String, SearchResultHit> getHitsMap()
077        {
078            return hits;
079        }
080    
081        public boolean isEmpty()
082        {
083            return hits.isEmpty();
084        }
085    
086        public SearchResultLimits getLimits()
087        {
088            return limits;
089        }
090    
091        public void setLimits( SearchResultLimits limits )
092        {
093            this.limits = limits;
094        }
095    
096        public int getTotalHits()
097        {
098            return totalHits;
099        }
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    }