List of usage examples for com.liferay.portal.kernel.search SearchContext setUserId
public void setUserId(long userId)
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); }/*from w w w .j av a 2 s . com*/ 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//from w ww.ja va 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); }//from www . j a va2 s .c o m 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 ww w .java 2s. 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.search.test.AssetSearcherStagingTest.java
License:Open Source License
@Test public void testSiteRolePermissions() throws Exception { Role role = addRole(RoleConstants.TYPE_SITE); String className = "com.liferay.journal.model.JournalArticle"; RoleTestUtil.addResourcePermission(role, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, "0", ActionKeys.VIEW);//from w ww.ja va2s . co m User user = addUser(); ServiceTestUtil.setUser(user); addUserGroupRole(user, role); addJournalArticle(); GroupTestUtil.enableLocalStaging(_group); SearchContext searchContext = getSearchContext(); Group stagingGroup = _group.getStagingGroup(); searchContext.setGroupIds(new long[] { stagingGroup.getGroupId() }); searchContext.setUserId(user.getUserId()); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.addSelectedFieldNames(Field.GROUP_ID, Field.STAGING_GROUP); AssetEntryQuery assetEntryQuery = getAssetEntryQuery(className); Hits hits = search(assetEntryQuery, searchContext); Document[] documents = hits.getDocs(); DocumentsAssert.assertCount(hits.toString(), documents, Field.COMPANY_ID, 1); Document document = documents[0]; assertField(document, Field.GROUP_ID, String.valueOf(stagingGroup.getGroupId())); assertField(document, Field.STAGING_GROUP, StringPool.TRUE); }
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)); }// ww w .j a va 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.search.test.CalendarBookingIndexerTest.java
License:Open Source License
protected static SearchContext getSearchContext(Group group, User user) throws Exception { SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId()); searchContext.setUserId(user.getUserId()); return searchContext; }
From source file:com.liferay.calendar.search.test.CalendarSearchFixture.java
License:Open Source License
public SearchContext getSearchContext(String keywords, Locale locale) { SearchContext searchContext = new SearchContext(); try {/*from www . j av a 2s. c o m*/ searchContext.setCompanyId(TestPropsValues.getCompanyId()); searchContext.setUserId(getUserId()); } catch (PortalException pe) { throw new RuntimeException(pe); } searchContext.setGroupIds(new long[] { _group.getGroupId() }); searchContext.setKeywords(keywords); searchContext.setLocale(Objects.requireNonNull(locale)); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setSelectedFieldNames(StringPool.STAR); return 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);/*from w w w . j a v a2s .co m*/ searchContext.setUserId(themeDisplay.getUserId()); Indexer<?> indexer = CalendarSearcher.getInstance(); return indexer.search(searchContext); }