Java tutorial
/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.docs.guestbook.search; import java.util.Locale; import org.osgi.service.component.annotations.Component; import com.liferay.petra.string.StringPool; import com.liferay.portal.kernel.search.Document; import com.liferay.portal.kernel.search.Field; import com.liferay.portal.kernel.search.Summary; import com.liferay.portal.search.spi.model.result.contributor.ModelSummaryContributor; @Component(immediate = true, property = "indexer.class.name=com.liferay.docs.guestbook.model.GuestbookEntry", service = ModelSummaryContributor.class) public class GuestbookEntryModelSummaryContributor implements ModelSummaryContributor { @Override public Summary getSummary(Document document, Locale locale, String snippet) { Summary summary = createSummary(document); summary.setMaxContentLength(128); return summary; } private Summary createSummary(Document document) { String prefix = Field.SNIPPET + StringPool.UNDERLINE; String title = document.get(prefix + Field.TITLE, Field.CONTENT); String content = document.get(prefix + Field.CONTENT, Field.CONTENT); return new Summary(title, content); } }