
META-INF.resources.search.search.jsp Maven / Gradle / Ivy
<%--
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%@ include file="/search/init.jsp" %>
<%
String keywords = ParamUtil.getString(request, "keywords");
String orderByCol = ParamUtil.getString(request, "orderByCol", "score");
String orderByType = ParamUtil.getString(request, "orderByType", "desc");
%>
<%
SearchContext searchContext = SearchContextFactory.getInstance(request);
searchContext.setAttribute("paginationType", "regular");
searchContext.setEnd(searchContainer.getEnd());
searchContext.setKeywords(keywords);
searchContext.setStart(searchContainer.getStart());
searchContext.setSorts(KBUtil.getKBArticleSorts(orderByCol, orderByType));
Indexer indexer = IndexerRegistryUtil.getIndexer(KBArticle.class);
Hits hits = indexer.search(searchContext);
List tuples = new ArrayList();
for (int i = 0; i < hits.getDocs().length; i++) {
Object[] array = new Object[5];
Document document = hits.doc(i);
array[0] = document.get(Field.ENTRY_CLASS_PK);
array[1] = document.get(Field.TITLE);
long userId = GetterUtil.getLong(document.get(Field.USER_ID));
String userName = document.get(Field.USER_NAME);
array[2] = PortalUtil.getUserName(userId, userName);
array[3] = document.getDate(Field.CREATE_DATE);
array[4] = document.getDate(Field.MODIFIED_DATE);
tuples.add(new Tuple(array));
}
searchContainer.setResults(tuples);
searchContainer.setTotal(hits.getLength());
%>
<%
KBArticle kbArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(GetterUtil.getLong((String)tuple.getObject(0)), WorkflowConstants.STATUS_APPROVED);
int viewCount = (kbArticle != null) ? kbArticle.getViewCount() : 0;
buffer.append(viewCount);
buffer.append(StringPool.SPACE);
buffer.append((viewCount == 1) ? LanguageUtil.get(request, "view") : LanguageUtil.get(request, "views"));
%>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy