1
19
20 package com.liferay.portlet.bookmarks.util;
21
22 import com.liferay.portal.kernel.search.Document;
23 import com.liferay.portal.kernel.search.DocumentImpl;
24 import com.liferay.portal.kernel.search.DocumentSummary;
25 import com.liferay.portal.kernel.search.Field;
26 import com.liferay.portal.kernel.search.SearchEngineUtil;
27 import com.liferay.portal.kernel.search.SearchException;
28 import com.liferay.portal.util.PortletKeys;
29 import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
30
31 import java.util.Date;
32
33 import javax.portlet.PortletURL;
34
35
42 public class Indexer implements com.liferay.portal.kernel.search.Indexer {
43
44 public static final String PORTLET_ID = PortletKeys.BOOKMARKS;
45
46 public static void addEntry(
47 long companyId, long groupId, long folderId, long entryId,
48 String name, String url, String comments, Date modifiedDate,
49 String[] tagsEntries)
50 throws SearchException {
51
52 Document doc = getEntryDocument(
53 companyId, groupId, folderId, entryId, name, url, comments,
54 modifiedDate, tagsEntries);
55
56 SearchEngineUtil.addDocument(companyId, doc);
57 }
58
59 public static void deleteEntry(long companyId, long entryId)
60 throws SearchException {
61
62 SearchEngineUtil.deleteDocument(companyId, getEntryUID(entryId));
63 }
64
65 public static Document getEntryDocument(
66 long companyId, long groupId, long folderId, long entryId, String name,
67 String url, String comments, Date modifiedDate, String[] tagsEntries) {
68
69 Document doc = new DocumentImpl();
70
71 doc.addUID(PORTLET_ID, entryId);
72
73 doc.addModifiedDate(modifiedDate);
74
75 doc.addKeyword(Field.COMPANY_ID, companyId);
76 doc.addKeyword(Field.PORTLET_ID, PORTLET_ID);
77 doc.addKeyword(Field.GROUP_ID, groupId);
78
79 doc.addText(Field.TITLE, name);
80 doc.addKeyword(Field.TAGS_ENTRIES, tagsEntries);
81
82 doc.addKeyword("folderId", folderId);
83 doc.addKeyword(Field.ENTRY_CLASS_PK, entryId);
84 doc.addText(Field.URL, url);
85 doc.addText(Field.COMMENTS, comments);
86
87 return doc;
88 }
89
90 public static String getEntryUID(long entryId) {
91 Document doc = new DocumentImpl();
92
93 doc.addUID(PORTLET_ID, entryId);
94
95 return doc.get(Field.UID);
96 }
97
98 public static void updateEntry(
99 long companyId, long groupId, long folderId, long entryId,
100 String name, String url, String comments, Date modifiedDate,
101 String[] tagsEntries)
102 throws SearchException {
103
104 Document doc = getEntryDocument(
105 companyId, groupId, folderId, entryId, name, url, comments,
106 modifiedDate, tagsEntries);
107
108 SearchEngineUtil.updateDocument(companyId, doc.get(Field.UID), doc);
109 }
110
111 public DocumentSummary getDocumentSummary(
112 com.liferay.portal.kernel.search.Document doc, PortletURL portletURL) {
113
114
116 String title = doc.get(Field.TITLE);
117
118
120 String url = doc.get(Field.URL);
121
122
124 String entryId = doc.get(Field.ENTRY_CLASS_PK);
125
126 portletURL.setParameter("struts_action", "/bookmarks/edit_entry");
127 portletURL.setParameter("entryId", entryId);
128
129 return new DocumentSummary(title, url, portletURL);
130 }
131
132 public void reIndex(String[] ids) throws SearchException {
133 try {
134 BookmarksFolderLocalServiceUtil.reIndex(ids);
135 }
136 catch (Exception e) {
137 throw new SearchException(e);
138 }
139 }
140
141 }