1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.search;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * <a href="HitsImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   * @author Bruno Farache
33   */
34  public class HitsImpl implements Hits {
35  
36      public HitsImpl() {
37      }
38  
39      public Document doc(int n) {
40          return _docs[n];
41      }
42  
43      public Document[] getDocs() {
44          return _docs;
45      }
46  
47      public int getLength() {
48          return _length;
49      }
50  
51      public String[] getQueryTerms() {
52          return _queryTerms;
53      }
54  
55      public float[] getScores() {
56          return _scores;
57      }
58  
59      public float getSearchTime() {
60          return _searchTime;
61      }
62  
63      public String[] getSnippets() {
64          return _snippets;
65      }
66  
67      public long getStart() {
68          return _start;
69      }
70  
71      public float score(int n) {
72          return _scores[n];
73      }
74  
75      public void setDocs(Document[] docs) {
76          _docs = docs;
77      }
78  
79      public void setLength(int length) {
80          _length = length;
81      }
82  
83      public void setQueryTerms(String[] queryTerms) {
84          _queryTerms = queryTerms;
85      }
86  
87      public void setScores(float[] scores) {
88          _scores = scores;
89      }
90  
91      public void setScores(Float[] scores) {
92          float[] primScores = new float[scores.length];
93  
94          for (int i = 0; i < scores.length; i++) {
95              primScores[i] = scores[i].floatValue();
96          }
97  
98          setScores(primScores);
99      }
100 
101     public void setSearchTime(float time) {
102         _searchTime = time;
103     }
104 
105     public void setSnippets(String[] snippets) {
106         _snippets = snippets;
107     }
108 
109     public void setStart(long start) {
110         _start = start;
111     }
112 
113     public String snippet(int n) {
114         return _snippets[n];
115     }
116 
117     public List<Document> toList() {
118         List<Document> subset = new ArrayList<Document>(_docs.length);
119 
120         for (int i = 0; i < _docs.length; i++) {
121             subset.add(_docs[i]);
122         }
123 
124         return subset;
125     }
126 
127     private Document[] _docs;
128     private int _length;
129     private String[] _queryTerms;
130     private float[] _scores = new float[0];
131     private float _searchTime;
132     private String[] _snippets;
133     private long _start;
134 
135 }