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