1
14
15 package com.liferay.portlet.assetpublisher.util;
16
17 import com.liferay.portal.kernel.search.BaseIndexer;
18 import com.liferay.portal.kernel.search.BooleanQuery;
19 import com.liferay.portal.kernel.search.Document;
20 import com.liferay.portal.kernel.search.Field;
21 import com.liferay.portal.kernel.search.SearchContext;
22 import com.liferay.portal.kernel.search.Summary;
23 import com.liferay.portal.kernel.util.Validator;
24 import com.liferay.portal.util.PortletKeys;
25 import com.liferay.portlet.asset.model.AssetEntry;
26
27 import javax.portlet.PortletURL;
28
29
35 public class AssetIndexer extends BaseIndexer {
36
37 public static final String[] CLASS_NAMES = {AssetEntry.class.getName()};
38
39 public static final String PORTLET_ID = PortletKeys.ASSET_PUBLISHER;
40
41 public String[] getClassNames() {
42 return CLASS_NAMES;
43 }
44
45 public Summary getSummary(
46 Document document, String snippet, PortletURL portletURL) {
47
48 return null;
49 }
50
51 protected void doDelete(Object obj) {
52 }
53
54 protected Document doGetDocument(Object obj) {
55 return null;
56 }
57
58 protected void doReindex(Object obj) {
59 }
60
61 protected void doReindex(String className, long classPK) {
62 }
63
64 protected void doReindex(String[] ids) {
65 }
66
67 protected String getPortletId(SearchContext searchContext) {
68 return PORTLET_ID;
69 }
70
71 protected void postProcessSearchQuery(
72 BooleanQuery searchQuery, SearchContext searchContext)
73 throws Exception {
74
75 if (searchContext.getAttributes() == null) {
76 return;
77 }
78
79 String description = (String)searchContext.getAttribute(
80 Field.DESCRIPTION);
81
82 if (Validator.isNotNull(description)) {
83 if (searchContext.isAndSearch()) {
84 searchQuery.addRequiredTerm(
85 Field.DESCRIPTION, description, true);
86 }
87 else {
88 searchQuery.addTerm(Field.DESCRIPTION, description, true);
89 }
90 }
91
92 String title = (String)searchContext.getAttribute(Field.TITLE);
93
94 if (Validator.isNotNull(title)) {
95 if (searchContext.isAndSearch()) {
96 searchQuery.addRequiredTerm(Field.TITLE, title, true);
97 }
98 else {
99 searchQuery.addTerm(Field.TITLE, title, true);
100 }
101 }
102
103 String userName = (String)searchContext.getAttribute(Field.USER_NAME);
104
105 if (Validator.isNotNull(userName)) {
106 if (searchContext.isAndSearch()) {
107 searchQuery.addRequiredTerm(Field.USER_NAME, userName, true);
108 }
109 else {
110 searchQuery.addTerm(Field.USER_NAME, userName, true);
111 }
112 }
113 }
114
115 }