1
22
23 package com.liferay.portlet.expando.model.impl;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.search.Document;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.kernel.util.UnicodeProperties;
31 import com.liferay.portlet.expando.model.ExpandoBridge;
32 import com.liferay.portlet.expando.model.ExpandoColumnConstants;
33 import com.liferay.portlet.expando.model.ExpandoTableConstants;
34 import com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil;
35 import com.liferay.portlet.expando.util.ExpandoBridgeIndexer;
36
37 import java.util.Enumeration;
38
39
45 public class ExpandoBridgeIndexerImpl implements ExpandoBridgeIndexer {
46
47 public void addAttributes(Document doc, ExpandoBridge expandoBridge) {
48 if (expandoBridge == null) {
49 return;
50 }
51
52 Enumeration<String> enu = expandoBridge.getAttributeNames();
53
54 while (enu.hasMoreElements()) {
55 String name = enu.nextElement();
56
57 int type = expandoBridge.getAttributeType(name);
58
59 UnicodeProperties properties = expandoBridge.getAttributeProperties(
60 name);
61
62 boolean indexable = GetterUtil.getBoolean(
63 properties.get(ExpandoBridgeIndexer.INDEXABLE));
64
65 if (!indexable || (type != ExpandoColumnConstants.STRING)) {
66 continue;
67 }
68
69 try {
70 String value = ExpandoValueLocalServiceUtil.getData(
71 expandoBridge.getClassName(),
72 ExpandoTableConstants.DEFAULT_TABLE_NAME, name,
73 expandoBridge.getClassPK(), StringPool.BLANK);
74
75 doc.addText(name, value);
76 }
77 catch (Exception e) {
78 _log.error("Indexing " + name, e);
79 }
80 }
81 }
82
83 private static Log _log =
84 LogFactoryUtil.getLog(ExpandoBridgeIndexerImpl.class);
85
86 }