List of usage examples for com.liferay.portal.kernel.search BaseModelSearchResult getLength
public int getLength()
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
private List<AssetEntryResult> _getAssetEntryResultsByClassName(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); int total = 0; for (long classNameId : classNameIds) { assetEntryQuery.setClassNameIds(new long[] { classNameId }); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);/*from w w w .j a v a2 s . c om*/ int groupTotal = baseModelSearchResult.getLength(); total += groupTotal; List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < groupTotal)) { AssetRendererFactory<?> groupAssetRendererFactory = AssetRendererFactoryRegistryUtil .getAssetRendererFactoryByClassNameId(classNameId); String title = ResourceActionsUtil.getModelResource(locale, groupAssetRendererFactory.getClassName()); assetEntryResults.add(new AssetEntryResult(title, assetEntries)); } if (!portletName.equals(AssetPublisherPortletKeys.RECENT_CONTENT)) { if (groupTotal > 0) { if ((end > 0) && (end > groupTotal)) { end -= groupTotal; } else { end = 0; } if ((start > 0) && (start > groupTotal)) { start -= groupTotal; } else { start = 0; } } assetEntryQuery.setEnd(QueryUtil.ALL_POS); assetEntryQuery.setStart(QueryUtil.ALL_POS); } } searchContainer.setTotal(total); return assetEntryResults; }
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
private List<AssetEntryResult> _getAssetEntryResultsByDefault(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); assetEntryQuery.setClassNameIds(classNameIds); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);/*w w w. ja va 2 s . co m*/ int total = baseModelSearchResult.getLength(); searchContainer.setTotal(total); List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < total)) { assetEntryResults.add(new AssetEntryResult(assetEntries)); } return assetEntryResults; }
From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java
License:Open Source License
private List<AssetEntryResult> _getAssetEntryResultsByVocabulary(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, long assetVocabularyId, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); List<AssetCategory> assetCategories = _assetCategoryLocalService .getVocabularyRootCategories(assetVocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); assetEntryQuery.setClassNameIds(classNameIds); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); int total = 0; for (AssetCategory assetCategory : assetCategories) { long[] oldAllCategoryIds = assetEntryQuery.getAllCategoryIds(); long[] newAllAssetCategoryIds = ArrayUtil.append(oldAllCategoryIds, assetCategory.getCategoryId()); assetEntryQuery.setAllCategoryIds(newAllAssetCategoryIds); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);/*from ww w . jav a 2s .c o m*/ int groupTotal = baseModelSearchResult.getLength(); total += groupTotal; List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < groupTotal)) { String title = assetCategory.getTitle(locale); assetEntryResults.add(new AssetEntryResult(title, assetEntries)); } if (groupTotal > 0) { if ((end > 0) && (end > groupTotal)) { end -= groupTotal; } else { end = 0; } if ((start > 0) && (start > groupTotal)) { start -= groupTotal; } else { start = 0; } } assetEntryQuery.setAllCategoryIds(oldAllCategoryIds); assetEntryQuery.setEnd(QueryUtil.ALL_POS); assetEntryQuery.setStart(QueryUtil.ALL_POS); } searchContainer.setTotal(total); return assetEntryResults; }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
protected static List<AssetEntryResult> getAssetEntryResultsByClassName(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); int total = 0; for (long classNameId : classNameIds) { assetEntryQuery.setClassNameIds(new long[] { classNameId }); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);/*from w w w. ja v a 2 s .co m*/ int groupTotal = baseModelSearchResult.getLength(); total += groupTotal; List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < groupTotal)) { AssetRendererFactory<?> groupAssetRendererFactory = AssetRendererFactoryRegistryUtil .getAssetRendererFactoryByClassNameId(classNameId); String title = ResourceActionsUtil.getModelResource(locale, groupAssetRendererFactory.getClassName()); assetEntryResults.add(new AssetEntryResult(title, assetEntries)); } if (!portletName.equals(AssetPublisherPortletKeys.RECENT_CONTENT)) { if (groupTotal > 0) { if ((end > 0) && (end > groupTotal)) { end -= groupTotal; } else { end = 0; } if ((start > 0) && (start > groupTotal)) { start -= groupTotal; } else { start = 0; } } assetEntryQuery.setEnd(QueryUtil.ALL_POS); assetEntryQuery.setStart(QueryUtil.ALL_POS); } } searchContainer.setTotal(total); return assetEntryResults; }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
protected static List<AssetEntryResult> getAssetEntryResultsByDefault(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); assetEntryQuery.setClassNameIds(classNameIds); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);/* ww w. j a v a 2 s .c o m*/ int total = baseModelSearchResult.getLength(); searchContainer.setTotal(total); List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < total)) { assetEntryResults.add(new AssetEntryResult(assetEntries)); } return assetEntryResults; }
From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java
License:Open Source License
protected static List<AssetEntryResult> getAssetEntryResultsByVocabulary(SearchContainer searchContainer, AssetEntryQuery assetEntryQuery, Layout layout, PortletPreferences portletPreferences, String portletName, Locale locale, TimeZone timeZone, long companyId, long scopeGroupId, long userId, long[] classNameIds, long assetVocabularyId, Map<String, Serializable> attributes) throws Exception { List<AssetEntryResult> assetEntryResults = new ArrayList<>(); List<AssetCategory> assetCategories = _assetCategoryLocalService .getVocabularyRootCategories(assetVocabularyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null); assetEntryQuery.setClassNameIds(classNameIds); int end = searchContainer.getEnd(); int start = searchContainer.getStart(); int total = 0; for (AssetCategory assetCategory : assetCategories) { long[] oldAllCategoryIds = assetEntryQuery.getAllCategoryIds(); long[] newAllAssetCategoryIds = ArrayUtil.append(oldAllCategoryIds, assetCategory.getCategoryId()); assetEntryQuery.setAllCategoryIds(newAllAssetCategoryIds); BaseModelSearchResult<AssetEntry> baseModelSearchResult = getAssetEntries(assetEntryQuery, layout, portletPreferences, portletName, locale, timeZone, companyId, scopeGroupId, userId, attributes, start, end);//from ww w . j a v a2s . co m int groupTotal = baseModelSearchResult.getLength(); total += groupTotal; List<AssetEntry> assetEntries = baseModelSearchResult.getBaseModels(); if (!assetEntries.isEmpty() && (start < groupTotal)) { String title = assetCategory.getTitle(locale); assetEntryResults.add(new AssetEntryResult(title, assetEntries)); } if (groupTotal > 0) { if ((end > 0) && (end > groupTotal)) { end -= groupTotal; } else { end = 0; } if ((start > 0) && (start > groupTotal)) { start -= groupTotal; } else { start = 0; } } assetEntryQuery.setAllCategoryIds(oldAllCategoryIds); assetEntryQuery.setEnd(QueryUtil.ALL_POS); assetEntryQuery.setStart(QueryUtil.ALL_POS); } searchContainer.setTotal(total); return assetEntryResults; }
From source file:com.liferay.asset.search.test.AssetTagsSearchTest.java
License:Open Source License
@Test public void testExactMatchSearch() throws Exception { AssetTagLocalServiceUtil.addTag(TestPropsValues.getUserId(), _group.getGroupId(), "tag", _serviceContext); AssetTagLocalServiceUtil.addTag(TestPropsValues.getUserId(), _group.getGroupId(), "tag1", _serviceContext); BaseModelSearchResult<AssetTag> searchResult = AssetTagLocalServiceUtil .searchTags(new long[] { _group.getGroupId() }, "\"tag\"", 0, 20, null); Assert.assertEquals(1, searchResult.getLength()); }
From source file:com.liferay.asset.search.test.AssetTagsSearchTest.java
License:Open Source License
@Test public void testNoMatchSearch() throws Exception { AssetTagLocalServiceUtil.addTag(TestPropsValues.getUserId(), _group.getGroupId(), "tag1", _serviceContext); AssetTagLocalServiceUtil.addTag(TestPropsValues.getUserId(), _group.getGroupId(), "tag2", _serviceContext); BaseModelSearchResult<AssetTag> searchResult = AssetTagLocalServiceUtil .searchTags(new long[] { _group.getGroupId() }, "\"tag\"", 0, 20, null); Assert.assertEquals(0, searchResult.getLength()); }
From source file:com.liferay.asset.tags.admin.web.internal.display.context.AssetTagsDisplayContext.java
License:Open Source License
public SearchContainer getTagsSearchContainer() throws PortalException { if (_tagsSearchContainer != null) { return _tagsSearchContainer; }//from w ww . j a va 2 s .c o m SearchContainer tagsSearchContainer = new SearchContainer(_renderRequest, _renderResponse.createRenderURL(), null, "there-are-no-tags"); String keywords = getKeywords(); if (Validator.isNull(keywords)) { if (isShowAddButton()) { tagsSearchContainer.setEmptyResultsMessage("there-are-no-tags.-you-can-add-a-tag-by-clicking-the-" + "plus-button-on-the-bottom-right-corner"); tagsSearchContainer .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn"); } } else { tagsSearchContainer.setSearch(true); } tagsSearchContainer.setRowChecker(new EmptyOnClickRowChecker(_renderResponse)); ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); if (Validator.isNotNull(keywords)) { Sort sort = null; String orderByCol = getOrderByCol(); if (orderByCol.equals("name")) { sort = SortFactoryUtil.getSort(AssetTag.class, Sort.STRING_TYPE, Field.NAME, getOrderByType()); } else if (orderByCol.equals("usages")) { sort = SortFactoryUtil.getSort(AssetTag.class, Sort.INT_TYPE, "assetCount_Number", getOrderByType()); } BaseModelSearchResult<AssetTag> baseModelSearchResult = AssetTagLocalServiceUtil.searchTags( new long[] { themeDisplay.getScopeGroupId() }, keywords, tagsSearchContainer.getStart(), tagsSearchContainer.getEnd(), sort); tagsSearchContainer.setResults(baseModelSearchResult.getBaseModels()); tagsSearchContainer.setTotal(baseModelSearchResult.getLength()); } else { String orderByCol = getOrderByCol(); tagsSearchContainer.setOrderByCol(orderByCol); OrderByComparator<AssetTag> orderByComparator = null; boolean orderByAsc = false; String orderByType = getOrderByType(); if (orderByType.equals("asc")) { orderByAsc = true; } if (orderByCol.equals("name")) { orderByComparator = new AssetTagNameComparator(orderByAsc); } else if (orderByCol.equals("usages")) { orderByComparator = new AssetTagAssetCountComparator(orderByAsc); } tagsSearchContainer.setOrderByComparator(orderByComparator); tagsSearchContainer.setOrderByType(orderByType); long scopeGroupId = themeDisplay.getScopeGroupId(); int tagsCount = AssetTagServiceUtil.getTagsCount(scopeGroupId, keywords); tagsSearchContainer.setTotal(tagsCount); List<AssetTag> tags = AssetTagServiceUtil.getTags(scopeGroupId, StringPool.BLANK, tagsSearchContainer.getStart(), tagsSearchContainer.getEnd(), tagsSearchContainer.getOrderByComparator()); tagsSearchContainer.setResults(tags); } _tagsSearchContainer = tagsSearchContainer; return _tagsSearchContainer; }
From source file:com.liferay.asset.util.test.AssetUtilTest.java
License:Open Source License
protected void assertCount(int expectedCount, AssetEntryQuery assetEntryQuery, long[] assetCategoryIds, String[] assetTagNames, Map<String, Serializable> attributes, long companyId, String keywords, Layout layout, Locale locale, long scopeGroupId, TimeZone timezone, long userId) throws Exception { BaseModelSearchResult<AssetEntry> baseModelSearchResult = _assetHelper.searchAssetEntries(assetEntryQuery, assetCategoryIds, assetTagNames, attributes, companyId, keywords, layout, locale, scopeGroupId, timezone, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS); Assert.assertEquals(baseModelSearchResult.toString(), expectedCount, baseModelSearchResult.getLength()); }