001
014
015 package com.liferay.portlet.trash.test;
016
017 import com.liferay.portal.kernel.dao.orm.QueryUtil;
018 import com.liferay.portal.kernel.search.Hits;
019 import com.liferay.portal.kernel.search.Indexer;
020 import com.liferay.portal.kernel.search.IndexerRegistryUtil;
021 import com.liferay.portal.kernel.search.SearchContext;
022 import com.liferay.portal.kernel.test.util.SearchContextTestUtil;
023 import com.liferay.portal.service.ServiceContext;
024 import com.liferay.portlet.trash.service.TrashEntryLocalServiceUtil;
025
026
029 public class DefaultWhenIsIndexableBaseModel
030 implements WhenIsIndexableBaseModel {
031
032 @Override
033 public String getSearchKeywords() {
034 return "Title";
035 }
036
037 @Override
038 public int searchBaseModelsCount(Class<?> clazz, long groupId)
039 throws Exception {
040
041 Indexer<?> indexer = IndexerRegistryUtil.getIndexer(clazz);
042
043 SearchContext searchContext = SearchContextTestUtil.getSearchContext();
044
045 searchContext.setGroupIds(new long[] {groupId});
046
047 Hits results = indexer.search(searchContext);
048
049 return results.getLength();
050 }
051
052 @Override
053 public int searchTrashEntriesCount(
054 String keywords, ServiceContext serviceContext)
055 throws Exception {
056
057 Hits results = TrashEntryLocalServiceUtil.search(
058 serviceContext.getCompanyId(), serviceContext.getScopeGroupId(),
059 serviceContext.getUserId(), keywords, QueryUtil.ALL_POS,
060 QueryUtil.ALL_POS, null);
061
062 return results.getLength();
063 }
064
065 }