1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.search;
16  
17  import java.util.ArrayList;
18  import java.util.List;
19  
20  /**
21   * <a href="HitsImpl.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   * @author Bruno Farache
25   */
26  public class HitsImpl implements Hits {
27  
28      public HitsImpl() {
29      }
30  
31      public Document doc(int n) {
32          return _docs[n];
33      }
34  
35      public Document[] getDocs() {
36          return _docs;
37      }
38  
39      public int getLength() {
40          return _length;
41      }
42  
43      public String[] getQueryTerms() {
44          return _queryTerms;
45      }
46  
47      public float[] getScores() {
48          return _scores;
49      }
50  
51      public float getSearchTime() {
52          return _searchTime;
53      }
54  
55      public String[] getSnippets() {
56          return _snippets;
57      }
58  
59      public long getStart() {
60          return _start;
61      }
62  
63      public float score(int n) {
64          return _scores[n];
65      }
66  
67      public void setDocs(Document[] docs) {
68          _docs = docs;
69      }
70  
71      public void setLength(int length) {
72          _length = length;
73      }
74  
75      public void setQueryTerms(String[] queryTerms) {
76          _queryTerms = queryTerms;
77      }
78  
79      public void setScores(float[] scores) {
80          _scores = scores;
81      }
82  
83      public void setScores(Float[] scores) {
84          float[] primScores = new float[scores.length];
85  
86          for (int i = 0; i < scores.length; i++) {
87              primScores[i] = scores[i].floatValue();
88          }
89  
90          setScores(primScores);
91      }
92  
93      public void setSearchTime(float time) {
94          _searchTime = time;
95      }
96  
97      public void setSnippets(String[] snippets) {
98          _snippets = snippets;
99      }
100 
101     public void setStart(long start) {
102         _start = start;
103     }
104 
105     public String snippet(int n) {
106         return _snippets[n];
107     }
108 
109     public List<Document> toList() {
110         List<Document> subset = new ArrayList<Document>(_docs.length);
111 
112         for (int i = 0; i < _docs.length; i++) {
113             subset.add(_docs[i]);
114         }
115 
116         return subset;
117     }
118 
119     private Document[] _docs;
120     private int _length;
121     private String[] _queryTerms;
122     private float[] _scores = new float[0];
123     private float _searchTime;
124     private String[] _snippets = {};
125     private long _start;
126 
127 }