1
19
20 package com.liferay.portlet.expando.model.impl;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.dao.orm.QueryUtil;
24 import com.liferay.portal.kernel.log.Log;
25 import com.liferay.portal.kernel.log.LogFactoryUtil;
26 import com.liferay.portal.kernel.search.Document;
27 import com.liferay.portal.kernel.util.GetterUtil;
28 import com.liferay.portal.kernel.util.UnicodeProperties;
29 import com.liferay.portlet.expando.model.ExpandoBridge;
30 import com.liferay.portlet.expando.model.ExpandoColumn;
31 import com.liferay.portlet.expando.model.ExpandoTableConstants;
32 import com.liferay.portlet.expando.model.ExpandoValue;
33 import com.liferay.portlet.expando.service.ExpandoColumnLocalServiceUtil;
34 import com.liferay.portlet.expando.service.ExpandoValueLocalServiceUtil;
35 import com.liferay.portlet.expando.util.ExpandoBridgeIndexer;
36
37 import java.util.ArrayList;
38 import java.util.List;
39
40
46 public class ExpandoBridgeIndexerImpl implements ExpandoBridgeIndexer {
47
48 public void addAttributes(Document doc, ExpandoBridge expandoBridge) {
49 if (expandoBridge == null) {
50 return;
51 }
52
53 try {
54 doAddAttributes(doc, expandoBridge);
55 }
56 catch (SystemException se) {
57 _log.error(se, se);
58 }
59 }
60
61 protected void doAddAttributes(Document doc, ExpandoBridge expandoBridge)
62 throws SystemException {
63
64 List<ExpandoColumn> expandoColumns =
65 ExpandoColumnLocalServiceUtil.getDefaultTableColumns(
66 expandoBridge.getClassName());
67
68 if ((expandoColumns == null) || expandoColumns.isEmpty()) {
69 return;
70 }
71
72 List<ExpandoColumn> indexedColumns = new ArrayList<ExpandoColumn>();
73
74 for (ExpandoColumn expandoColumn : expandoColumns) {
75 UnicodeProperties properties =
76 expandoColumn.getTypeSettingsProperties();
77
78 boolean indexable = GetterUtil.getBoolean(
79 properties.get(ExpandoBridgeIndexer.INDEXABLE));
80
81 if (indexable) {
82 indexedColumns.add(expandoColumn);
83 }
84 }
85
86 if (indexedColumns.isEmpty()) {
87 return;
88 }
89
90 List<ExpandoValue> expandoValues =
91 ExpandoValueLocalServiceUtil.getRowValues(
92 expandoBridge.getClassName(),
93 ExpandoTableConstants.DEFAULT_TABLE_NAME,
94 expandoBridge.getClassPK(), QueryUtil.ALL_POS,
95 QueryUtil.ALL_POS);
96
97 for (ExpandoColumn expandoColumn : indexedColumns) {
98 try {
99 String value = expandoColumn.getDefaultData();
100
101 for (ExpandoValue expandoValue : expandoValues) {
102 if (expandoValue.getColumnId() ==
103 expandoColumn.getColumnId()) {
104
105 value = expandoValue.getData();
106
107 break;
108 }
109 }
110
111 doc.addText(expandoColumn.getName(), value);
112 }
113 catch (Exception e) {
114 _log.error("Indexing " + expandoColumn.getName(), e);
115 }
116 }
117 }
118
119 private static Log _log =
120 LogFactoryUtil.getLog(ExpandoBridgeIndexerImpl.class);
121
122 }