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.portal.kernel.util.Validator;
25 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
26 import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
27 import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
28
29 import javax.portlet.PortletRequest;
30 import javax.portlet.PortletURL;
31 import javax.portlet.WindowStateException;
32
33
39 public class Indexer implements com.liferay.portal.kernel.search.Indexer {
40
41 public String[] getClassNames() {
42 return _CLASS_NAMES;
43 }
44
45 public DocumentSummary getDocumentSummary(
46 Document doc, String snippet, PortletURL portletURL) {
47
48 LiferayPortletURL liferayPortletURL = (LiferayPortletURL)portletURL;
49
50 liferayPortletURL.setLifecycle(PortletRequest.ACTION_PHASE);
51
52 try {
53 liferayPortletURL.setWindowState(LiferayWindowState.EXCLUSIVE);
54 }
55 catch (WindowStateException wse) {
56 }
57
58
60 String repositoryId = doc.get("repositoryId");
61 String fileName = doc.get("path");
62
63 String title = fileName;
64
65
67 String content = snippet;
68
69 if (Validator.isNull(snippet)) {
70 content = StringUtil.shorten(doc.get(Field.CONTENT), 200);
71 }
72
73
75 portletURL.setParameter("struts_action", "/document_library/get_file");
76 portletURL.setParameter("folderId", repositoryId);
77 portletURL.setParameter("name", fileName);
78
79 return new DocumentSummary(title, content, portletURL);
80 }
81
82 public void reIndex(String className, long classPK) throws SearchException {
83 try {
84 DLFileEntryLocalServiceUtil.reIndex(classPK);
85 }
86 catch (Exception e) {
87 throw new SearchException(e);
88 }
89 }
90
91 public void reIndex(String[] ids) throws SearchException {
92 try {
93 DLFolderLocalServiceUtil.reIndex(ids);
94 }
95 catch (Exception e) {
96 throw new SearchException(e);
97 }
98 }
99
100 private static final String[] _CLASS_NAMES = new String[] {
101 DLFileEntry.class.getName()
102 };
103
104 }