List of usage examples for com.liferay.portal.kernel.search SearchContext setAttribute
public void setAttribute(String name, Serializable value)
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 {/* ww w . j ava2 s.c o 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 . ja v a2s .c o 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.sample.service.impl.SearchLocalServiceImpl.java
License:Open Source License
/** * NOTE FOR DEVELOPERS:/*from ww w. j a va 2 s . co m*/ * * Never reference this interface directly. Always use {@link com.liferay.portlet.sample.service.SearchLocalServiceUtil} to access the search local service. */ public List<JournalArticle> searchWC(String structureKey, String fieldName, Serializable fieldValue, ThemeDisplay themeDisplay) { List<JournalArticle> articles = new ArrayList<JournalArticle>(); try { SearchContext searchContext = new SearchContext(); int start = QueryUtil.ALL_POS; int end = QueryUtil.ALL_POS; LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); Map<String, Serializable> searchByFields = new LinkedHashMap<String, Serializable>(); searchByFields.put(fieldName, fieldValue); params.put(SampleConstants.STRUCTURE_FIELDS, searchByFields); params.put(SampleConstants.STRUCTURE_KEY, structureKey); params.put(SampleConstants.STRUCTURE_GROUP_ID, themeDisplay.getScopeGroupId()); Map<String, Serializable> attributes = new HashMap<String, Serializable>(); attributes.put("params", params); searchContext.setAttributes(attributes); searchContext.setAndSearch(true); searchContext.setCompanyId(themeDisplay.getCompanyId()); searchContext.setGroupIds(new long[] { PortalUtil.getSiteGroupId(themeDisplay.getScopeGroupId()) }); searchContext.setAttribute("paginationType", "none"); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false); searchContext.setQueryConfig(queryConfig); searchContext.setStart(start); searchContext.setEnd(end); Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(JournalArticle.class); articles = getJournalArticles(indexer.search(searchContext)); } catch (Exception e) { _log.error(e); } return articles; }
From source file:com.liferay.users.admin.indexer.test.UserIndexerTest.java
License:Open Source License
protected Hits search(String field, String value) throws Exception { SearchContext searchContext = getSearchContext(); searchContext.setAttribute(field, value); return search(searchContext); }
From source file:com.liferay.wiki.web.internal.display.context.DefaultWikiListPagesDisplayContext.java
License:Open Source License
@Override public void populateResultsAndTotal(SearchContainer searchContainer) throws PortalException { WikiPage page = (WikiPage) _request.getAttribute(WikiWebKeys.WIKI_PAGE); ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); String navigation = ParamUtil.getString(_request, "navigation", "all-pages"); String keywords = ParamUtil.getString(_request, "keywords"); int total = 0; List<WikiPage> results = new ArrayList<>(); if (Validator.isNotNull(keywords)) { Indexer<WikiPage> indexer = IndexerRegistryUtil.getIndexer(WikiPage.class); SearchContext searchContext = SearchContextFactory.getInstance(_request); searchContext.setAttribute("paginationType", "more"); searchContext.setEnd(searchContainer.getEnd()); searchContext.setIncludeAttachments(true); searchContext.setIncludeDiscussions(true); searchContext.setKeywords(keywords); searchContext.setNodeIds(new long[] { _wikiNode.getNodeId() }); searchContext.setStart(searchContainer.getStart()); Hits hits = indexer.search(searchContext); searchContainer.setTotal(hits.getLength()); List<SearchResult> searchResults = SearchResultUtil.getSearchResults(hits, themeDisplay.getLocale()); for (SearchResult searchResult : searchResults) { WikiPage wikiPage = WikiPageLocalServiceUtil.getPage(searchResult.getClassPK()); results.add(wikiPage);//from ww w . j a va 2s. c o m } } else if (navigation.equals("all-pages")) { total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true, themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED); searchContainer.setTotal(total); OrderByComparator<WikiPage> obc = WikiPortletUtil .getPageOrderByComparator(searchContainer.getOrderByCol(), searchContainer.getOrderByType()); results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), true, themeDisplay.getUserId(), true, WorkflowConstants.STATUS_APPROVED, searchContainer.getStart(), searchContainer.getEnd(), obc); } else if (navigation.equals("categorized-pages") || navigation.equals("tagged-pages")) { AssetEntryQuery assetEntryQuery = new AssetEntryQuery(WikiPage.class.getName(), searchContainer); assetEntryQuery.setEnablePermissions(true); total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery); searchContainer.setTotal(total); assetEntryQuery.setEnd(searchContainer.getEnd()); assetEntryQuery.setStart(searchContainer.getStart()); List<AssetEntry> assetEntries = AssetEntryServiceUtil.getEntries(assetEntryQuery); for (AssetEntry assetEntry : assetEntries) { WikiPageResource pageResource = WikiPageResourceLocalServiceUtil .getPageResource(assetEntry.getClassPK()); WikiPage assetPage = WikiPageLocalServiceUtil.getPage(pageResource.getNodeId(), pageResource.getTitle()); results.add(assetPage); } } else if (navigation.equals("draft-pages") || navigation.equals("pending-pages")) { long draftUserId = themeDisplay.getUserId(); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (permissionChecker.isContentReviewer(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId())) { draftUserId = 0; } int status = WorkflowConstants.STATUS_DRAFT; if (navigation.equals("pending-pages")) { status = WorkflowConstants.STATUS_PENDING; } total = WikiPageServiceUtil.getPagesCount(themeDisplay.getScopeGroupId(), draftUserId, _wikiNode.getNodeId(), status); searchContainer.setTotal(total); results = WikiPageServiceUtil.getPages(themeDisplay.getScopeGroupId(), draftUserId, _wikiNode.getNodeId(), status, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("frontpage")) { WikiWebComponentProvider wikiWebComponentProvider = WikiWebComponentProvider .getWikiWebComponentProvider(); WikiGroupServiceConfiguration wikiGroupServiceConfiguration = wikiWebComponentProvider .getWikiGroupServiceConfiguration(); WikiPage wikiPage = WikiPageServiceUtil.getPage(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), wikiGroupServiceConfiguration.frontPageName()); searchContainer.setTotal(1); results.add(wikiPage); } else if (navigation.equals("history")) { total = WikiPageLocalServiceUtil.getPagesCount(page.getNodeId(), page.getTitle()); searchContainer.setTotal(total); results = WikiPageLocalServiceUtil.getPages(page.getNodeId(), page.getTitle(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, new PageVersionComparator()); } else if (navigation.equals("incoming-links")) { List<WikiPage> links = WikiPageLocalServiceUtil.getIncomingLinks(page.getNodeId(), page.getTitle()); total = links.size(); searchContainer.setTotal(total); results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("orphan-pages")) { List<WikiPage> orphans = WikiPageServiceUtil.getOrphans(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId()); total = orphans.size(); searchContainer.setTotal(total); results = ListUtil.subList(orphans, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("outgoing-links")) { List<WikiPage> links = WikiPageLocalServiceUtil.getOutgoingLinks(page.getNodeId(), page.getTitle()); total = links.size(); searchContainer.setTotal(total); results = ListUtil.subList(links, searchContainer.getStart(), searchContainer.getEnd()); } else if (navigation.equals("recent-changes")) { total = WikiPageServiceUtil.getRecentChangesCount(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId()); searchContainer.setTotal(total); results = WikiPageServiceUtil.getRecentChanges(themeDisplay.getScopeGroupId(), _wikiNode.getNodeId(), searchContainer.getStart(), searchContainer.getEnd()); } searchContainer.setResults(results); }
From source file:com.portlet.sample.service.impl.SampleEntryLocalServiceImpl.java
License:Open Source License
@Override public Hits search(long companyId, String title, String content, int start, int end) throws PortalException, SystemException { Indexer indexer = IndexerRegistryUtil.getIndexer(SampleEntry.class.getName()); SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setStart(start);/*w ww . jav a2 s. c om*/ searchContext.setEnd(end); searchContext.setAttribute(Field.TITLE, title); searchContext.setAttribute(Field.CONTENT, content); return indexer.search(searchContext); }