List of usage examples for com.liferay.portal.kernel.search SearchContext getCompanyId
public long getCompanyId()
From source file:com.ext.portlet.Activity.ActivityUtil.java
License:Open Source License
private static Hits getAggregatedActivitySearchResults(long userId, int start, int end) throws SearchException { SearchContext context = new SearchContext(); context.setCompanyId(DEFAULT_COMPANY_ID); BooleanQuery query = BooleanQueryFactoryUtil.create(context); query.addRequiredTerm(Field.ENTRY_CLASS_NAME, SocialActivity.class.getName()); BooleanQuery subQuery = BooleanQueryFactoryUtil.create(context); subQuery.addExactTerm("userId", userId); try {/*from www.j a va 2s. c om*/ query.add(subQuery, BooleanClauseOccur.MUST); } catch (ParseException e) { _log.error(e); } Sort sort = SortFactoryUtil.create("createDate", Sort.FLOAT_TYPE, true); return SearchEngineUtil.search(SearchEngineUtil.getDefaultSearchEngineId(), context.getCompanyId(), query, sort, start, end); }
From source file:com.ext.portlet.Activity.ActivityUtil.java
License:Open Source License
private static Hits getAggregatedActivitySearchResultsExcludingUsers(List<Long> excludedUserIds, int start, int end) throws SearchException { SearchContext context = new SearchContext(); context.setCompanyId(DEFAULT_COMPANY_ID); BooleanQuery query = BooleanQueryFactoryUtil.create(context); query.addRequiredTerm(Field.ENTRY_CLASS_NAME, SocialActivity.class.getName()); BooleanQuery excludeQuery = BooleanQueryFactoryUtil.create(context); for (Long excludedUserId : excludedUserIds) { excludeQuery.addExactTerm("userId", excludedUserId); }//from w w w . j a va 2 s .c o m try { query.add(excludeQuery, BooleanClauseOccurImpl.MUST_NOT); } catch (ParseException e) { _log.error(e); } Sort sort = SortFactoryUtil.create("createDate", Sort.FLOAT_TYPE, true); return SearchEngineUtil.search(SearchEngineUtil.getDefaultSearchEngineId(), context.getCompanyId(), query, sort, start, end); }
From source file:com.liferay.calendar.search.CalendarBookingIndexer.java
License:Open Source License
@Override public BooleanFilter getFacetBooleanFilter(String className, SearchContext searchContext) throws Exception { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.addTerm(Field.ENTRY_CLASS_NAME, CalendarBooking.class.getName()); if (searchContext.getUserId() > 0) { SearchPermissionChecker searchPermissionChecker = SearchEngineHelperUtil.getSearchPermissionChecker(); booleanFilter = searchPermissionChecker.getPermissionBooleanFilter(searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), Calendar.class.getName(), booleanFilter, searchContext);// www . j a va 2 s .com } return booleanFilter; }
From source file:com.liferay.dynamic.data.lists.internal.search.DDLRecordIndexer.java
License:Open Source License
@Override public BooleanFilter getFacetBooleanFilter(String className, SearchContext searchContext) throws Exception { BooleanFilter facetBooleanFilter = new BooleanFilter(); facetBooleanFilter.addTerm(Field.ENTRY_CLASS_NAME, DDLRecord.class.getName()); if (searchContext.getUserId() > 0) { facetBooleanFilter = searchPermissionChecker.getPermissionBooleanFilter(searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), DDLRecordSet.class.getName(), facetBooleanFilter, searchContext); }/*w ww .ja v a 2s . co m*/ return facetBooleanFilter; }
From source file:com.liferay.dynamic.data.mapping.internal.search.DDMFormInstanceRecordIndexer.java
License:Open Source License
@Override public BooleanFilter getFacetBooleanFilter(String className, SearchContext searchContext) throws Exception { BooleanFilter facetBooleanFilter = new BooleanFilter(); facetBooleanFilter.addTerm(Field.ENTRY_CLASS_NAME, DDMFormInstanceRecord.class.getName()); if (searchContext.getUserId() > 0) { facetBooleanFilter = searchPermissionChecker.getPermissionBooleanFilter(searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), DDMFormInstance.class.getName(), facetBooleanFilter, searchContext); }//from www . ja va 2 s.co m return facetBooleanFilter; }
From source file:com.liferay.exportimport.search.ExportImportConfigurationIndexer.java
License:Open Source License
@Override public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception { addStatus(contextBooleanFilter, searchContext); contextBooleanFilter.addRequiredTerm(Field.COMPANY_ID, searchContext.getCompanyId()); contextBooleanFilter.addRequiredTerm(Field.GROUP_ID, GetterUtil.getLong(searchContext.getAttribute(Field.GROUP_ID))); Serializable type = searchContext.getAttribute(Field.TYPE); if (type != null) { contextBooleanFilter.addRequiredTerm(Field.TYPE, GetterUtil.getInteger(type)); }//www. ja va 2s. c o m }
From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception { Group group = GroupLocalServiceUtil.getCompanyGroup(searchContext.getCompanyId()); DDMStructure tikaRawMetadataStructure = DDMStructureLocalServiceUtil.fetchStructure(group.getGroupId(), PortalUtil.getClassNameId(RawMetadataProcessor.class), "TikaRawMetadata"); if (tikaRawMetadataStructure != null) { addSearchDDMStruture(searchQuery, searchContext, tikaRawMetadataStructure); }//from w ww . j a va 2 s . c o m String keywords = searchContext.getKeywords(); if (Validator.isNull(keywords)) { addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false); addSearchTerm(searchQuery, searchContext, Field.TITLE, false); addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false); } addSearchTerm(searchQuery, searchContext, "ddmContent", false); addSearchTerm(searchQuery, searchContext, "extension", false); addSearchTerm(searchQuery, searchContext, "fileEntryTypeId", false); addSearchTerm(searchQuery, searchContext, "path", false); LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params"); if (params != null) { String expandoAttributes = (String) params.get("expandoAttributes"); if (Validator.isNotNull(expandoAttributes)) { addSearchExpando(searchQuery, searchContext, expandoAttributes); } } }
From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext) throws Exception { Set<DDMStructure> ddmStructuresSet = new TreeSet<DDMStructure>(); long[] groupIds = searchContext.getGroupIds(); if ((groupIds != null) && (groupIds.length > 0)) { List<DLFileEntryType> dlFileEntryTypes = DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(groupIds); for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) { ddmStructuresSet.addAll(dlFileEntryType.getDDMStructures()); }/*w w w . ja va 2s .c om*/ } Group group = GroupLocalServiceUtil.getCompanyGroup(searchContext.getCompanyId()); DDMStructure tikaRawMetadataStructure = DDMStructureLocalServiceUtil.fetchStructure(group.getGroupId(), "TikaRawMetadata"); if (tikaRawMetadataStructure != null) { ddmStructuresSet.add(tikaRawMetadataStructure); } for (DDMStructure ddmStructure : ddmStructuresSet) { addSearchDDMStruture(searchQuery, searchContext, ddmStructure); } addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false); addSearchTerm(searchQuery, searchContext, "extension", false); addSearchTerm(searchQuery, searchContext, "fileEntryTypeId", false); addSearchTerm(searchQuery, searchContext, "path", false); LinkedHashMap<String, Object> params = (LinkedHashMap<String, Object>) searchContext.getAttribute("params"); if (params != null) { String expandoAttributes = (String) params.get("expandoAttributes"); if (Validator.isNotNull(expandoAttributes)) { addSearchExpando(searchQuery, searchContext, expandoAttributes); } } }
From source file:com.liferay.trash.internal.search.TrashIndexer.java
License:Open Source License
@Override public BooleanQuery getFullQuery(SearchContext searchContext) throws SearchException { try {/*from w w w .j a v a 2s. com*/ BooleanFilter fullQueryBooleanFilter = new BooleanFilter(); fullQueryBooleanFilter.addRequiredTerm(Field.COMPANY_ID, searchContext.getCompanyId()); List<TrashHandler> trashHandlers = TrashHandlerRegistryUtil.getTrashHandlers(); for (TrashHandler trashHandler : trashHandlers) { Filter filter = trashHandler.getExcludeFilter(searchContext); if (filter != null) { fullQueryBooleanFilter.add(filter, BooleanClauseOccur.MUST_NOT); } processTrashHandlerExcludeQuery(searchContext, fullQueryBooleanFilter, trashHandler); } long[] groupIds = searchContext.getGroupIds(); if (ArrayUtil.isNotEmpty(groupIds)) { TermsFilter groupTermsFilter = new TermsFilter(Field.GROUP_ID); groupTermsFilter.addValues(ArrayUtil.toStringArray(groupIds)); fullQueryBooleanFilter.add(groupTermsFilter, BooleanClauseOccur.MUST); } fullQueryBooleanFilter.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_IN_TRASH); BooleanQuery fullQuery = createFullQuery(fullQueryBooleanFilter, searchContext); return fullQuery; } catch (SearchException se) { throw se; } catch (Exception e) { throw new SearchException(e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexSearcher.java
License:Open Source License
private Query getPermissionQuery(SearchContext searchContext, Query query) { if (searchContext.getEntryClassNames() == null) { return query; }/*from ww w . j a v a 2 s . c o m*/ for (String className : searchContext.getEntryClassNames()) { Indexer indexer = IndexerRegistryUtil.getIndexer(className); if (indexer != null) { if (indexer.isFilterSearch() && indexer.isPermissionAware()) { SearchPermissionChecker searchPermissionChecker = SearchEngineUtil.getSearchPermissionChecker(); query = searchPermissionChecker.getPermissionQuery(searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), className, query, searchContext); } } } return query; }