List of usage examples for com.liferay.portal.kernel.search SearchContext setAttribute
public void setAttribute(String name, Serializable value)
From source file:ch.inofix.contact.service.impl.ContactLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long userId, long groupId, long ownerUserId, String company, String fullName, int status, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort) throws PortalException { SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, status); if (Validator.isNotNull(company)) { searchContext.setAttribute("company", company); }/*www. j a v a 2s . c om*/ if (Validator.isNotNull(fullName)) { searchContext.setAttribute("fullName", fullName); } searchContext.setAttribute("paginationType", "more"); Group group = GroupLocalServiceUtil.getGroup(groupId); searchContext.setCompanyId(group.getCompanyId()); if (ownerUserId > 0) { searchContext.setOwnerUserId(ownerUserId); } searchContext.setEnd(end); if (groupId > 0) { searchContext.setGroupIds(new long[] { groupId }); } searchContext.setSorts(sort); searchContext.setStart(start); searchContext.setUserId(userId); searchContext.setAndSearch(andSearch); if (params != null) { String keywords = (String) params.remove("keywords"); if (Validator.isNotNull(keywords)) { searchContext.setKeywords(keywords); } } QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); if (sort != null) { searchContext.setSorts(sort); } searchContext.setStart(start); return searchContext; }
From source file:ch.inofix.referencemanager.service.impl.BibliographyServiceImpl.java
License:Open Source License
/** * @param userId// w w w . j a v a 2 s . c o m * the userId of the current user * @param groupId * the scopeGroupId of the bibliography. 0 means: any scope. * @param ownerUserId * the userId of the bibliography owner. -1 means: ignore * ownerUserId parameter. * @param keywords * @param start * @param end * @param sort * @return the hits for the given parameters * @since 1.0.0 * @throws PortalException */ public Hits search(long userId, long groupId, long ownerUserId, String keywords, int start, int end, Sort sort) throws PortalException { if (sort == null) { sort = new Sort(Field.MODIFIED_DATE, true); } Indexer<Bibliography> indexer = IndexerRegistryUtil.getIndexer(Bibliography.class.getName()); SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY); searchContext.setAttribute("paginationType", "more"); User user = UserLocalServiceUtil.getUser(userId); searchContext.setCompanyId(user.getCompanyId()); searchContext.setEnd(end); if (groupId > 0) { searchContext.setGroupIds(new long[] { groupId }); } searchContext.setSorts(sort); searchContext.setStart(start); searchContext.setUserId(userId); searchContext.setOwnerUserId(ownerUserId); return indexer.search(searchContext); }
From source file:ch.inofix.referencemanager.service.impl.ReferenceLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long userId, long groupId, long bibliographyId, String author, String title, String year, int status, LinkedHashMap<String, Object> params, boolean andSearch, int start, int end, Sort sort) throws PortalException { SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, status); if (Validator.isNotNull(author)) { searchContext.setAttribute("author", author); }/* w ww. j av a2 s .c om*/ if (bibliographyId > 0) { searchContext.setAttribute("bibliographyId", bibliographyId); } if (Validator.isNotNull(title)) { searchContext.setAttribute("title", title); } if (Validator.isNotNull(year)) { searchContext.setAttribute("year", year); } searchContext.setAttribute("paginationType", "more"); Group group = GroupLocalServiceUtil.getGroup(groupId); searchContext.setCompanyId(group.getCompanyId()); searchContext.setEnd(end); if (groupId > 0) { searchContext.setGroupIds(new long[] { groupId }); } searchContext.setSorts(sort); searchContext.setStart(start); searchContext.setUserId(userId); searchContext.setAndSearch(andSearch); if (params != null) { String keywords = (String) params.remove("keywords"); if (Validator.isNotNull(keywords)) { searchContext.setKeywords(keywords); } } QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); if (sort != null) { searchContext.setSorts(sort); } searchContext.setStart(start); return searchContext; }
From source file:ch.inofix.timetracker.service.impl.TaskRecordLocalServiceImpl.java
License:Open Source License
@Override public Hits search(long userId, long groupId, String keywords, int start, int end, Sort sort) throws PortalException { if (sort == null) { sort = new Sort(Field.MODIFIED_DATE, true); }/*from w ww .j a va 2 s . com*/ Indexer<TaskRecord> indexer = IndexerRegistryUtil.getIndexer(TaskRecord.class.getName()); SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY); searchContext.setAttribute("paginationType", "more"); Group group = GroupLocalServiceUtil.getGroup(groupId); searchContext.setCompanyId(group.getCompanyId()); searchContext.setEnd(end); if (groupId > 0) { searchContext.setGroupIds(new long[] { groupId }); } searchContext.setSorts(sort); searchContext.setStart(start); searchContext.setUserId(userId); searchContext.setKeywords(keywords); return indexer.search(searchContext); }
From source file:com.liferay.asset.categories.internal.search.AssetCategoryIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter, SearchContext searchContext) throws Exception { String title = (String) searchContext.getAttribute(Field.TITLE); if (Validator.isNotNull(title)) { BooleanQuery localizedQuery = new BooleanQueryImpl(); searchContext.setAttribute(Field.ASSET_CATEGORY_TITLE, title); addSearchLocalizedTerm(localizedQuery, searchContext, Field.ASSET_CATEGORY_TITLE, true); addSearchLocalizedTerm(localizedQuery, searchContext, Field.TITLE, true); searchQuery.add(localizedQuery, BooleanClauseOccur.SHOULD); }/*from ww w . java 2 s. c om*/ }
From source file:com.liferay.asset.internal.util.AssetHelperImpl.java
License:Open Source License
private AssetSearcher _getAssetSearcher(SearchContext searchContext, AssetEntryQuery assetEntryQuery, int start, int end) throws Exception { Indexer<?> searcher = AssetSearcher.getInstance(); AssetSearcher assetSearcher = (AssetSearcher) searcher; assetSearcher.setAssetEntryQuery(assetEntryQuery); Layout layout = assetEntryQuery.getLayout(); if (layout != null) { searchContext.setAttribute(Field.LAYOUT_UUID, layout.getUuid()); }/*from w ww .ja v a 2s .com*/ String ddmStructureFieldName = (String) assetEntryQuery.getAttribute("ddmStructureFieldName"); Serializable ddmStructureFieldValue = assetEntryQuery.getAttribute("ddmStructureFieldValue"); if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) { searchContext.setAttribute("ddmStructureFieldName", ddmStructureFieldName); searchContext.setAttribute("ddmStructureFieldValue", ddmStructureFieldValue); } String paginationType = GetterUtil.getString(assetEntryQuery.getPaginationType(), "more"); if (!paginationType.equals("none") && !paginationType.equals("simple")) { searchContext.setAttribute("paginationType", paginationType); } searchContext.setClassTypeIds(assetEntryQuery.getClassTypeIds()); searchContext.setEnd(end); searchContext.setGroupIds(assetEntryQuery.getGroupIds()); if (Validator.isNull(assetEntryQuery.getKeywords())) { QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setScoreEnabled(false); } else { searchContext.setLike(true); } searchContext.setSorts(_getSorts(assetEntryQuery, searchContext.getLocale())); searchContext.setStart(start); return assetSearcher; }
From source file:com.liferay.asset.search.test.AssetUtilSearchSortTest.java
License:Open Source License
protected SearchContext createSearchContext() { SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.GROUP_ID, _group.getGroupId()); searchContext.setCompanyId(_group.getCompanyId()); searchContext.setGroupIds(new long[] { _group.getGroupId() }); searchContext.setKeywords(StringPool.BLANK); searchContext.setUserId(_group.getCreatorUserId()); return searchContext; }
From source file:com.liferay.bookmarks.service.impl.BookmarksEntryLocalServiceImpl.java
License:Open Source License
@Override public Hits search(long groupId, long userId, long creatorUserId, int status, int start, int end) throws PortalException { Indexer<BookmarksEntry> indexer = IndexerRegistryUtil.getIndexer(BookmarksEntry.class.getName()); SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, status); if (creatorUserId > 0) { searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId)); }// w ww .j a v a 2 s . c o m searchContext.setAttribute("paginationType", "none"); Group group = groupLocalService.getGroup(groupId); searchContext.setCompanyId(group.getCompanyId()); searchContext.setEnd(end); searchContext.setGroupIds(new long[] { groupId }); searchContext.setSorts(new Sort(Field.MODIFIED_DATE, true)); searchContext.setStart(start); searchContext.setUserId(userId); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); return indexer.search(searchContext); }
From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java
License:Open Source License
protected Hits search(ThemeDisplay themeDisplay, String keywords) throws Exception { SearchContext searchContext = new SearchContext(); keywords = StringUtil.toLowerCase(keywords); searchContext.setAttribute(Field.NAME, keywords); searchContext.setAttribute("resourceName", keywords); searchContext.setCompanyId(themeDisplay.getCompanyId()); searchContext.setEnd(SearchContainer.DEFAULT_DELTA); searchContext.setGroupIds(new long[0]); Group group = themeDisplay.getScopeGroup(); searchContext.setIncludeStagingGroups(group.isStagingGroup()); searchContext.setStart(0);//w w w.j av a2 s . c om searchContext.setUserId(themeDisplay.getUserId()); Indexer<?> indexer = CalendarSearcher.getInstance(); return indexer.search(searchContext); }
From source file:com.liferay.document.library.service.test.DLAppServiceTest.java
License:Open Source License
protected static void search(FileEntry fileEntry, String keywords, boolean expected) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setAttribute("paginationType", "regular"); searchContext.setCompanyId(fileEntry.getCompanyId()); searchContext.setFolderIds(new long[] { fileEntry.getFolderId() }); searchContext.setGroupIds(new long[] { fileEntry.getRepositoryId() }); searchContext.setKeywords(keywords); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false);/*from w ww . j av a2s. c o m*/ Indexer<DLFileEntry> indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName()); Hits hits = indexer.search(searchContext); boolean found = false; for (Document document : hits.getDocs()) { long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); if (fileEntryId == fileEntry.getFileEntryId()) { found = true; break; } } Assert.assertEquals(hits.toString(), expected, found); }