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