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