001
014
015 package com.liferay.portlet.journalcontentsearch.util;
016
017 import com.liferay.portal.kernel.search.Document;
018 import com.liferay.portal.kernel.search.Field;
019 import com.liferay.portal.kernel.search.Hits;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.Time;
022 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
023
024 import java.util.ArrayList;
025 import java.util.List;
026
027
031 public class ContentHits {
032
033 public void recordHits(
034 Hits hits, long groupId, boolean privateLayout, int start, int end)
035 throws Exception {
036
037
038
039 List<Document> docs = new ArrayList<Document>();
040 List<Float> scores = new ArrayList<Float>();
041
042 for (int i = 0; i < hits.getLength(); i++) {
043 Document doc = hits.doc(i);
044
045 String articleId = doc.get(Field.ENTRY_CLASS_PK);
046 long articleGroupId = GetterUtil.getLong(doc.get(Field.GROUP_ID));
047
048 if (JournalContentSearchLocalServiceUtil.getLayoutIdsCount(
049 groupId, privateLayout, articleId) > 0) {
050
051 docs.add(hits.doc(i));
052 scores.add(hits.score(i));
053 }
054 else if (!isShowListed() && (articleGroupId == groupId)) {
055 docs.add(hits.doc(i));
056 scores.add(hits.score(i));
057 }
058 }
059
060 int length = docs.size();
061
062 hits.setLength(length);
063
064 if (end > length) {
065 end = length;
066 }
067
068 docs = docs.subList(start, end);
069
070 hits.setDocs(docs.toArray(new Document[docs.size()]));
071 hits.setScores(scores.toArray(new Float[docs.size()]));
072
073 hits.setSearchTime(
074 (float)(System.currentTimeMillis() - hits.getStart()) /
075 Time.SECOND);
076 }
077
078 public boolean isShowListed() {
079 return _showListed;
080 }
081
082 public void setShowListed(boolean showListed) {
083 _showListed = showListed;
084 }
085
086 private boolean _showListed = true;
087
088 }