01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions 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: */package com.liferay.portlet.journalcontentsearch.util;
22:
23: import com.liferay.portal.kernel.search.Document;
24: import com.liferay.portal.kernel.search.Hits;
25: import com.liferay.portal.kernel.util.GetterUtil;
26: import com.liferay.portal.lucene.LuceneFields;
27: import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
28: import com.liferay.util.Time;
29: import com.liferay.util.lucene.HitsImpl;
30:
31: import java.util.ArrayList;
32: import java.util.List;
33:
34: /**
35: * <a href="ContentHits.java.html"><b><i>View Source</i></b></a>
36: *
37: * @author Alexander Chow
38: * @author Raymond Augé
39: *
40: */
41: public class ContentHits extends HitsImpl {
42:
43: public ContentHits() {
44: super ();
45: }
46:
47: public void recordHits(Hits hits, long groupId,
48: boolean privateLayout) throws Exception {
49:
50: setSearcher(((HitsImpl) hits).getSearcher());
51:
52: // This can later be optimized according to LEP-915.
53:
54: List docs = new ArrayList(hits.getLength());
55: List scores = new ArrayList(hits.getLength());
56:
57: for (int i = 0; i < hits.getLength(); i++) {
58: Document doc = hits.doc(i);
59:
60: String articleId = doc.get("articleId");
61: long articleGroupId = GetterUtil.getLong(doc
62: .get(LuceneFields.GROUP_ID));
63:
64: if (JournalContentSearchLocalServiceUtil.getLayoutIdsCount(
65: groupId, privateLayout, articleId) > 0) {
66:
67: docs.add(hits.doc(i));
68: scores.add(new Float(hits.score(i)));
69: } else if (!isShowListed() && (articleGroupId == groupId)) {
70: docs.add(hits.doc(i));
71: scores.add(new Float(hits.score(i)));
72: }
73: }
74:
75: setLength(docs.size());
76: setDocs((Document[]) docs.toArray(new Document[0]));
77: setScores((Float[]) scores.toArray(new Float[0]));
78:
79: setSearchTime((float) (System.currentTimeMillis() - getStart())
80: / Time.SECOND);
81: }
82:
83: public boolean isShowListed() {
84: return _showListed;
85: }
86:
87: public void setShowListed(boolean showListed) {
88: _showListed = showListed;
89: }
90:
91: private boolean _showListed = true;
92:
93: }
|