List of usage examples for com.liferay.portal.kernel.search SearchContext setUserId
public void setUserId(long userId)
From source file:com.liferay.content.targeting.service.test.service.ServiceTestUtil.java
License:Open Source License
public static SearchContext getSearchContext(long groupId) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(TestPropsValues.getCompanyId()); searchContext.setGroupIds(new long[] { groupId }); searchContext.setUserId(TestPropsValues.getUserId()); return searchContext; }
From source file:com.liferay.dynamic.data.lists.search.test.DDLRecordSearchTest.java
License:Open Source License
protected static SearchContext getSearchContext(Group group, User user, DDLRecordSet recordSet) throws Exception { SearchContext searchContext = SearchContextTestUtil.getSearchContext(group.getGroupId()); searchContext.setAttribute("recordSetId", recordSet.getRecordSetId()); searchContext.setAttribute("status", WorkflowConstants.STATUS_ANY); searchContext.setUserId(user.getUserId()); return searchContext; }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long groupId, long userId, long creatorUserId, int status, int start, int end) throws PortalException { SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, status); searchContext.setAttribute("paginationType", "none"); if (creatorUserId > 0) { searchContext.setAttribute(Field.USER_ID, String.valueOf(creatorUserId)); }// w ww . j av a 2s . co m 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); return searchContext; }
From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java
License:Open Source License
@Override public Hits search(long companyId, long[] groupIds, long userId, String className, String keywords, int status, int start, int end) throws SystemException { try {/* w ww.j a v a 2 s . co m*/ SearchContext searchContext = new SearchContext(); Facet assetEntriesFacet = new AssetEntriesFacet(searchContext); assetEntriesFacet.setStatic(true); searchContext.addFacet(assetEntriesFacet); Facet scopeFacet = new ScopeFacet(searchContext); scopeFacet.setStatic(true); searchContext.addFacet(scopeFacet); searchContext.setAttribute("paginationType", "regular"); searchContext.setAttribute("status", status); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setEntryClassNames(getClassNames(companyId, className)); searchContext.setGroupIds(groupIds); searchContext.setKeywords(keywords); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); searchContext.setStart(start); searchContext.setUserId(userId); Indexer indexer = FacetedSearcher.getInstance(); return indexer.search(searchContext); } catch (Exception e) { throw new SystemException(e); } }
From source file:com.liferay.portlet.asset.service.impl.AssetEntryLocalServiceImpl.java
License:Open Source License
@Override public Hits search(long companyId, long[] groupIds, long userId, String className, String userName, String title, String description, String assetCategoryIds, String assetTagNames, int status, boolean andSearch, int start, int end) throws SystemException { try {/*from ww w . j a va 2 s . co m*/ SearchContext searchContext = new SearchContext(); Facet assetEntriesFacet = new AssetEntriesFacet(searchContext); assetEntriesFacet.setStatic(true); searchContext.addFacet(assetEntriesFacet); Facet scopeFacet = new ScopeFacet(searchContext); scopeFacet.setStatic(true); searchContext.addFacet(scopeFacet); searchContext.setAndSearch(andSearch); searchContext.setAssetCategoryIds(StringUtil.split(assetCategoryIds, 0L)); searchContext.setAssetTagNames(StringUtil.split(assetTagNames)); searchContext.setAttribute(Field.DESCRIPTION, description); searchContext.setAttribute(Field.TITLE, title); searchContext.setAttribute(Field.USER_NAME, userName); searchContext.setAttribute("paginationType", "regular"); searchContext.setAttribute("status", status); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setEntryClassNames(getClassNames(companyId, className)); searchContext.setGroupIds(groupIds); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); searchContext.setStart(start); searchContext.setUserId(userId); Indexer indexer = FacetedSearcher.getInstance(); return indexer.search(searchContext); } catch (Exception e) { throw new SystemException(e); } }
From source file:com.liferay.portlet.documentlibrary.store.DLStoreImpl.java
License:Open Source License
public Hits search(long companyId, long userId, String portletId, long groupId, long[] repositoryIds, String keywords, int start, int end) throws SystemException { try {// w w w. j a v a 2 s .c o m SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEnd(end); searchContext.setEntryClassNames(new String[] { DLFileEntryConstants.getClassName() }); searchContext.setGroupIds(new long[] { groupId }); Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName()); searchContext.setSearchEngineId(indexer.getSearchEngineId()); searchContext.setStart(start); searchContext.setUserId(userId); BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext); contextQuery.addRequiredTerm(Field.PORTLET_ID, portletId); if (groupId > 0) { Group group = groupLocalService.getGroup(groupId); if (group.isLayout()) { contextQuery.addRequiredTerm(Field.SCOPE_GROUP_ID, groupId); groupId = group.getParentGroupId(); } contextQuery.addRequiredTerm(Field.GROUP_ID, groupId); } if ((repositoryIds != null) && (repositoryIds.length > 0)) { BooleanQuery repositoryIdsQuery = BooleanQueryFactoryUtil.create(searchContext); for (long repositoryId : repositoryIds) { try { if (userId > 0) { PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); DLFolderPermission.check(permissionChecker, groupId, repositoryId, ActionKeys.VIEW); } if (repositoryId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) { repositoryId = groupId; } TermQuery termQuery = TermQueryFactoryUtil.create(searchContext, "repositoryId", repositoryId); repositoryIdsQuery.add(termQuery, BooleanClauseOccur.SHOULD); } catch (Exception e) { } } contextQuery.add(repositoryIdsQuery, BooleanClauseOccur.MUST); } BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); searchQuery.addTerms(_KEYWORDS_FIELDS, keywords); BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); fullQuery.add(contextQuery, BooleanClauseOccur.MUST); if (searchQuery.clauses().size() > 0) { fullQuery.add(searchQuery, BooleanClauseOccur.MUST); } return SearchEngineUtil.search(searchContext, fullQuery); } catch (Exception e) { throw new SystemException(e); } }
From source file:com.liferay.trash.service.impl.TrashEntryLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long companyId, long groupId, long userId, String keywords, int start, int end, Sort sort) { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEnd(end);/* w ww .ja v a 2s. c om*/ searchContext.setKeywords(keywords); searchContext.setGroupIds(new long[] { groupId }); if (sort != null) { searchContext.setSorts(sort); } searchContext.setStart(start); searchContext.setUserId(userId); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); return searchContext; }
From source file:com.vportal.portal.search.HitsOpenSearchImpl.java
License:Open Source License
public String search(HttpServletRequest request, long groupId, long userId, String keywords, int startPage, int itemsPerPage, String format) throws SearchException { try {/* ww w . j a v a 2 s .com*/ ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); int start = (startPage * itemsPerPage) - itemsPerPage; int end = startPage * itemsPerPage; SearchContext searchContext = SearchContextFactory.getInstance(request); searchContext.setGroupIds(new long[] { groupId }); searchContext.setEnd(end); searchContext.setKeywords(keywords); searchContext.setScopeStrict(false); searchContext.setStart(start); searchContext.setUserId(userId); addSearchAttributes(themeDisplay.getCompanyId(), searchContext, keywords); Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), getPortletId()); Indexer indexer = portlet.getIndexerInstance(); Hits results = indexer.search(searchContext); String[] queryTerms = results.getQueryTerms(); int total = results.getLength(); Object[] values = addSearchResults(queryTerms, keywords, startPage, itemsPerPage, total, start, getTitle(keywords), getSearchPath(), format, themeDisplay); com.liferay.portal.kernel.xml.Document doc = (com.liferay.portal.kernel.xml.Document) values[0]; Element root = (Element) values[1]; for (int i = 0; i < results.getDocs().length; i++) { Document result = results.doc(i); String portletId = result.get(Field.PORTLET_ID); String snippet = results.snippet(i); long resultGroupId = GetterUtil.getLong(result.get(Field.GROUP_ID)); PortletURL portletURL = getPortletURL(request, portletId, resultGroupId); Summary summary = getSummary(indexer, result, snippet, portletURL); String title = summary.getTitle(); String url = getURL(themeDisplay, resultGroupId, result, portletURL); Date modifedDate = result.getDate(Field.MODIFIED); String content = summary.getContent(); String[] tags = new String[0]; Field assetTagNamesField = result.getFields().get(Field.ASSET_TAG_NAMES); if (assetTagNamesField != null) { tags = assetTagNamesField.getValues(); } double ratings = 0.0; String entryClassName = result.get(Field.ENTRY_CLASS_NAME); long entryClassPK = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK)); if ((Validator.isNotNull(entryClassName)) && (entryClassPK > 0)) { RatingsStats stats = RatingsStatsLocalServiceUtil.getStats(entryClassName, entryClassPK); ratings = stats.getTotalScore(); } double score = results.score(i); addSearchResult(root, resultGroupId, entryClassName, entryClassPK, title, url, modifedDate, content, tags, ratings, score, format); } if (_log.isDebugEnabled()) { _log.debug("Return\n" + doc.asXML()); } return doc.asXML(); } catch (Exception e) { throw new SearchException(e); } }