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