diff --git a/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-lucene/xwiki-platform-lucene-api/src/main/java/com/xpn/xwiki/plugin/lucene/internal/DocumentData.java b/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-lucene/xwiki-platform-lucene-api/src/main/java/com/xpn/xwiki/plugin/lucene/internal/DocumentData.java index c3cc6b5..a299c0a 100644 --- a/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-lucene/xwiki-platform-lucene-api/src/main/java/com/xpn/xwiki/plugin/lucene/internal/DocumentData.java +++ b/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-lucene/xwiki-platform-lucene-api/src/main/java/com/xpn/xwiki/plugin/lucene/internal/DocumentData.java @@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.xwiki.model.reference.EntityReference; import org.xwiki.model.reference.EntityReferenceSerializer; import com.xpn.xwiki.XWikiContext; @@ -35,8 +36,10 @@ import com.xpn.xwiki.objects.PropertyInterface; import com.xpn.xwiki.objects.classes.BaseClass; import com.xpn.xwiki.objects.classes.DateClass; +import com.xpn.xwiki.objects.classes.DBListClass; import com.xpn.xwiki.objects.classes.ListItem; import com.xpn.xwiki.objects.classes.PasswordClass; +import com.xpn.xwiki.objects.classes.PropertyClass; import com.xpn.xwiki.objects.classes.StaticListClass; import com.xpn.xwiki.plugin.lucene.LucenePlugin; import com.xpn.xwiki.web.Utils; @@ -154,23 +157,37 @@ public void addDocumentDataToLuceneDocument(Document luceneDoc, XWikiDocument do private void indexProperty(Document luceneDoc, BaseObject baseObject, String propertyName, XWikiContext context) { String fieldFullName = baseObject.getClassName() + "." + propertyName; - BaseClass bClass = baseObject.getXClass(context); - PropertyInterface prop = bClass.getField(propertyName); - if (prop instanceof PasswordClass) { - // Do not index passwords - } else if (prop instanceof StaticListClass && ((StaticListClass) prop).isMultiSelect()) { - indexStaticList(luceneDoc, baseObject, (StaticListClass) prop, propertyName, context); - } else if (prop instanceof DateClass) { - // Date properties are indexed the same as document dates: formatted through IndexFields.dateToString() and - // untokenized, to be able to sort by their values. - addFieldToDocument(fieldFullName, getContentAsDate(baseObject, propertyName), Field.Store.YES, - Field.Index.NOT_ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); - } else { - StringBuilder sb = new StringBuilder(); - getObjectContentAsText(sb, baseObject, propertyName, context); - addFieldToDocument(fieldFullName, sb.toString(), Field.Store.YES, Field.Index.ANALYZED, - OBJECT_PROPERTY_BOOST, luceneDoc); + BaseClass xClass = baseObject.getXClass(context); + BaseProperty property = (BaseProperty) baseObject.getField(propertyName); + PropertyClass propertyClass = (PropertyClass) xClass.get(property.getName()); + + Object propertyValue = property.getValue(); + if (propertyValue != null) { + if (propertyClass instanceof PasswordClass) { + // Do not index passwords + } else if (propertyClass instanceof StaticListClass && ((StaticListClass) propertyClass).isMultiSelect()) { + indexStaticList(luceneDoc, baseObject, (StaticListClass) propertyClass, propertyName, context); + } else if (propertyClass instanceof DateClass) { + // Date properties are indexed the same as document dates: formatted through IndexFields.dateToString() + // and untokenized, to be able to sort by their values. + addFieldToDocument(fieldFullName, getContentAsDate(baseObject, propertyName), Field.Store.YES, + Field.Index.NOT_ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); + } else if (propertyValue instanceof List) { + // Handle list property values, by adding each list entry. + List propertyListValues = (List) propertyValue; + for (Object propertyListValue : propertyListValues) { + if (propertyListValue != null) { + addFieldToDocument(fieldFullName, String.format("%s", propertyListValue), Field.Store.YES, + Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); + } + } + } else { + StringBuilder sb = new StringBuilder(); + getObjectContentAsText(sb, baseObject, propertyName, context); + addFieldToDocument(fieldFullName, sb.toString(), Field.Store.YES, Field.Index.ANALYZED, + OBJECT_PROPERTY_BOOST, luceneDoc); + } } }