1
19
20 package com.liferay.portlet.journalcontentsearch.util;
21
22 import com.liferay.portal.kernel.search.Document;
23 import com.liferay.portal.kernel.search.Field;
24 import com.liferay.portal.kernel.search.Hits;
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.Time;
27 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32
39 public class ContentHits {
40
41 public void recordHits(
42 Hits hits, long groupId, boolean privateLayout, int start, int end)
43 throws Exception {
44
45
47 List<Document> docs = new ArrayList<Document>();
48 List<Float> scores = new ArrayList<Float>();
49
50 for (int i = 0; i < hits.getLength(); i++) {
51 Document doc = hits.doc(i);
52
53 String articleId = doc.get(Field.ENTRY_CLASS_PK);
54 long articleGroupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
55
56 if (JournalContentSearchLocalServiceUtil.getLayoutIdsCount(
57 groupId, privateLayout, articleId) > 0) {
58
59 docs.add(hits.doc(i));
60 scores.add(hits.score(i));
61 }
62 else if (!isShowListed() && (articleGroupId == groupId)) {
63 docs.add(hits.doc(i));
64 scores.add(hits.score(i));
65 }
66 }
67
68 int length = docs.size();
69
70 hits.setLength(length);
71
72 if (end > length) {
73 end = length;
74 }
75
76 docs = docs.subList(start, end);
77
78 hits.setDocs(docs.toArray(new Document[docs.size()]));
79 hits.setScores(scores.toArray(new Float[docs.size()]));
80
81 hits.setSearchTime(
82 (float)(System.currentTimeMillis() - hits.getStart()) /
83 Time.SECOND);
84 }
85
86 public boolean isShowListed() {
87 return _showListed;
88 }
89
90 public void setShowListed(boolean showListed) {
91 _showListed = showListed;
92 }
93
94 private boolean _showListed = true;
95
96 }