1
19
20 package com.liferay.portlet.documentlibrary.util;
21
22 import com.liferay.portal.kernel.portlet.LiferayPortletURL;
23 import com.liferay.portal.kernel.portlet.LiferayWindowState;
24 import com.liferay.portal.kernel.search.Document;
25 import com.liferay.portal.kernel.search.DocumentSummary;
26 import com.liferay.portal.kernel.search.Field;
27 import com.liferay.portal.kernel.search.SearchException;
28 import com.liferay.portal.kernel.util.StringUtil;
29 import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
30
31 import javax.portlet.PortletRequest;
32 import javax.portlet.PortletURL;
33 import javax.portlet.WindowStateException;
34
35
41 public class Indexer implements com.liferay.portal.kernel.search.Indexer {
42
43 public DocumentSummary getDocumentSummary(
44 Document doc, PortletURL portletURL) {
45
46 LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
47
48 liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);
49
50 try {
51 liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
52 }
53 catch (WindowStateException wse) {
54 }
55
56
58 String repositoryId = doc.get("repositoryId");
59 String fileName = doc.get("path");
60
61 String title = fileName;
62
63
65 String content = doc.get(Field.CONTENT);
66
67 content = StringUtil.shorten(content, 200);
68
69
71 portletURL.setParameter("struts_action", "/document_library/get_file");
72 portletURL.setParameter("folderId", repositoryId);
73 portletURL.setParameter("name", fileName);
74
75 return new DocumentSummary(title, content, portletURL);
76 }
77
78 public void reIndex(String[] ids) throws SearchException {
79 try {
80 DLFolderLocalServiceUtil.reIndex(ids);
81 }
82 catch (Exception e) {
83 throw new SearchException(e);
84 }
85 }
86
87 }