001
014
015 package com.liferay.portal.kernel.search;
016
017 import com.liferay.portal.kernel.json.JSON;
018
019 import java.util.ArrayList;
020 import java.util.List;
021
022
026 public class HitsImpl implements Hits {
027
028 public HitsImpl() {
029 }
030
031 public Document doc(int n) {
032 return _docs[n];
033 }
034
035 @JSON
036 public Document[] getDocs() {
037 return _docs;
038 }
039
040 public int getLength() {
041 return _length;
042 }
043
044 @JSON(include = false)
045 public Query getQuery() {
046 return _query;
047 }
048
049 @JSON
050 public String[] getQueryTerms() {
051 return _queryTerms;
052 }
053
054 @JSON
055 public float[] getScores() {
056 return _scores;
057 }
058
059 public float getSearchTime() {
060 return _searchTime;
061 }
062
063 @JSON
064 public String[] getSnippets() {
065 return _snippets;
066 }
067
068 public long getStart() {
069 return _start;
070 }
071
072 public float score(int n) {
073 return _scores[n];
074 }
075
076 public void setDocs(Document[] docs) {
077 _docs = docs;
078 }
079
080 public void setLength(int length) {
081 _length = length;
082 }
083
084 public void setQuery(Query query) {
085 _query = query;
086 }
087
088 public void setQueryTerms(String[] queryTerms) {
089 _queryTerms = queryTerms;
090 }
091
092 public void setScores(float[] scores) {
093 _scores = scores;
094 }
095
096 public void setScores(Float[] scores) {
097 float[] primScores = new float[scores.length];
098
099 for (int i = 0; i < scores.length; i++) {
100 primScores[i] = scores[i].floatValue();
101 }
102
103 setScores(primScores);
104 }
105
106 public void setSearchTime(float time) {
107 _searchTime = time;
108 }
109
110 public void setSnippets(String[] snippets) {
111 _snippets = snippets;
112 }
113
114 public void setStart(long start) {
115 _start = start;
116 }
117
118 public String snippet(int n) {
119 return _snippets[n];
120 }
121
122 public List<Document> toList() {
123 List<Document> subset = new ArrayList<Document>(_docs.length);
124
125 for (Document _doc : _docs) {
126 subset.add(_doc);
127 }
128
129 return subset;
130 }
131
132 private Document[] _docs;
133 private int _length;
134 private Query _query;
135 private String[] _queryTerms;
136 private float[] _scores = new float[0];
137 private float _searchTime;
138 private String[] _snippets = {};
139 private long _start;
140
141 }