001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.search;
016    
017    import java.util.ArrayList;
018    import java.util.List;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     * @author Bruno Farache
023     */
024    public class HitsImpl implements Hits {
025    
026            public HitsImpl() {
027            }
028    
029            public Document doc(int n) {
030                    return _docs[n];
031            }
032    
033            public Document[] getDocs() {
034                    return _docs;
035            }
036    
037            public int getLength() {
038                    return _length;
039            }
040    
041            public String[] getQueryTerms() {
042                    return _queryTerms;
043            }
044    
045            public float[] getScores() {
046                    return _scores;
047            }
048    
049            public float getSearchTime() {
050                    return _searchTime;
051            }
052    
053            public String[] getSnippets() {
054                    return _snippets;
055            }
056    
057            public long getStart() {
058                    return _start;
059            }
060    
061            public float score(int n) {
062                    return _scores[n];
063            }
064    
065            public void setDocs(Document[] docs) {
066                    _docs = docs;
067            }
068    
069            public void setLength(int length) {
070                    _length = length;
071            }
072    
073            public void setQueryTerms(String[] queryTerms) {
074                    _queryTerms = queryTerms;
075            }
076    
077            public void setScores(float[] scores) {
078                    _scores = scores;
079            }
080    
081            public void setScores(Float[] scores) {
082                    float[] primScores = new float[scores.length];
083    
084                    for (int i = 0; i < scores.length; i++) {
085                            primScores[i] = scores[i].floatValue();
086                    }
087    
088                    setScores(primScores);
089            }
090    
091            public void setSearchTime(float time) {
092                    _searchTime = time;
093            }
094    
095            public void setSnippets(String[] snippets) {
096                    _snippets = snippets;
097            }
098    
099            public void setStart(long start) {
100                    _start = start;
101            }
102    
103            public String snippet(int n) {
104                    return _snippets[n];
105            }
106    
107            public List<Document> toList() {
108                    List<Document> subset = new ArrayList<Document>(_docs.length);
109    
110                    for (int i = 0; i < _docs.length; i++) {
111                            subset.add(_docs[i]);
112                    }
113    
114                    return subset;
115            }
116    
117            private Document[] _docs;
118            private int _length;
119            private String[] _queryTerms;
120            private float[] _scores = new float[0];
121            private float _searchTime;
122            private String[] _snippets = {};
123            private long _start;
124    
125    }