Index: main/plugin-odf/plugin.xml =================================================================== --- main/plugin-odf/plugin.xml (revision 36748) +++ main/plugin-odf/plugin.xml (working copy) @@ -413,6 +413,9 @@ + + Index: main/plugin-odf/src/org/ametys/odf/contenttype/ODFContentIndexer.java =================================================================== --- main/plugin-odf/src/org/ametys/odf/contenttype/ODFContentIndexer.java (revision 36748) +++ main/plugin-odf/src/org/ametys/odf/contenttype/ODFContentIndexer.java (working copy) @@ -25,31 +25,36 @@ import org.apache.lucene.document.Field.Store; import org.ametys.cms.FilterNameHelper; +import org.ametys.cms.contenttype.ContentType; import org.ametys.cms.contenttype.DefaultContentIndexer; +import org.ametys.cms.contenttype.MetadataSet; import org.ametys.cms.repository.Content; import org.ametys.odf.program.Program; import org.ametys.odf.program.SubProgram; import org.ametys.plugins.repository.AmetysObject; import org.ametys.plugins.repository.AmetysObjectIterable; +import org.ametys.plugins.repository.metadata.CompositeMetadata; /** * ODF content specific indexer. */ public class ODFContentIndexer extends DefaultContentIndexer { - /** The avalon role. */ @SuppressWarnings("hiding") public static final String ROLE = ODFContentIndexer.class.getName(); + + /** The metadata indexer for subprograms in programs. */ + protected SubProgramMetadataIndexer _spMetadataIndexer; @Override public void service(ServiceManager manager) throws ServiceException { super.service(manager); _metadataIndexer = (ODFMetadataIndexer) manager.lookup(ODFMetadataIndexer.ROLE); + _spMetadataIndexer = (SubProgramMetadataIndexer) manager.lookup(SubProgramMetadataIndexer.ROLE); } - @Override public void indexContent(Content content, Document document, Map parameters) throws Exception { @@ -64,8 +69,33 @@ { String path = FilterNameHelper.filterName(((Content) child).getTitle()) + "-" + child.getName(); document.add(new Field("subprograms", path + ";" + ((Content) child).getTitle(), Store.YES, Index.NOT_ANALYZED)); + indexSubProgram((Content) child, document); } } } } + + /** + * Index metadata of subprograms in program. + * @param content + * @param document + * @throws Exception + */ + protected void indexSubProgram(Content content, Document document) throws Exception + { + CompositeMetadata metadata = content.getMetadataHolder(); + ContentType contentType = _contentTypeEP.getExtension(content.getType()); + + MetadataSet metadataSet = contentType.getMetadataSetForView("index"); + + if (metadataSet != null) + { + _spMetadataIndexer.indexMetadataSet(metadataSet, metadata, "", null, content, contentType, document); + } + else + { + // no metadataset named "index", so let's index only rich texts. + _spMetadataIndexer.indexFullTextRichTexts(metadata, document); + } + } } Index: main/plugin-odf/src/org/ametys/odf/contenttype/ODFMetadataIndexer.java =================================================================== --- main/plugin-odf/src/org/ametys/odf/contenttype/ODFMetadataIndexer.java (revision 36748) +++ main/plugin-odf/src/org/ametys/odf/contenttype/ODFMetadataIndexer.java (working copy) @@ -25,7 +25,6 @@ import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; import org.xml.sax.SAXException; - import org.ametys.cms.contenttype.ContentType; import org.ametys.cms.contenttype.MetadataDefinition; import org.ametys.cms.contenttype.MetadataSetElement; @@ -117,13 +116,13 @@ for (String value : parentOrgUnitsToIndex) { - document.add(new Field(FieldNames.FULL, value, Store.NO, Index.ANALYZED)); - document.add(new Field(fieldName, value, Store.YES, definition.getEnumerator() == null ? Index.ANALYZED : Index.NOT_ANALYZED)); + document.add(new Field(getGlobalPrefix() + FieldNames.FULL, value, Store.NO, Index.ANALYZED)); + document.add(new Field(getGlobalPrefix() + fieldName, value, Store.YES, definition.getEnumerator() == null ? Index.ANALYZED : Index.NOT_ANALYZED)); String[] words = StringUtils.split(value); for (String word : words) { - document.add(new Field(FieldNames.ALL_NOT_ANALYZED, StringUtils.strip(word, ",?!:()[].{}=").toLowerCase(), Store.NO, Index.NOT_ANALYZED)); + document.add(new Field(getGlobalPrefix() + FieldNames.ALL_NOT_ANALYZED, StringUtils.strip(word, ",?!:()[].{}=").toLowerCase(), Store.NO, Index.NOT_ANALYZED)); } } } Index: main/plugin-odf/src/org/ametys/odf/contenttype/SubProgramMetadataIndexer.java =================================================================== --- main/plugin-odf/src/org/ametys/odf/contenttype/SubProgramMetadataIndexer.java (revision 0) +++ main/plugin-odf/src/org/ametys/odf/contenttype/SubProgramMetadataIndexer.java (revision 0) @@ -0,0 +1,33 @@ +/* + * Copyright 2015 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ametys.odf.contenttype; + +/** + * Metadata indexer specific to ODF contents, which handles synchronized metadata values. + */ +public class SubProgramMetadataIndexer extends ODFMetadataIndexer +{ + /** The avalon role. */ + public static final String ROLE = SubProgramMetadataIndexer.class.getName(); + + public static final String INDEX_PREFIX_SUBPROGRAM = "sb_"; + + @Override + protected String getGlobalPrefix() + { + return INDEX_PREFIX_SUBPROGRAM; + } +}