List of usage examples for com.liferay.portal.kernel.search SearchContext getAttribute
public Serializable getAttribute(String name)
From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java
License:Open Source License
protected AlloySearchResult search(Indexer indexer, AlloyServiceInvoker alloyServiceInvoker, HttpServletRequest request, PortletRequest portletRequest, SearchContainer<? extends BaseModel<?>> searchContainer, Map<String, Serializable> attributes, String keywords, Sort[] sorts) throws Exception { if (indexer == null) { throw new Exception("No indexer found for " + controllerPath); }// w w w .ja v a 2 s.com AlloySearchResult alloySearchResult = new AlloySearchResult(); alloySearchResult.setAlloyServiceInvoker(alloyServiceInvoker); if (searchContainer == null) { searchContainer = new SearchContainer<BaseModel<?>>(portletRequest, portletURL, null, null); } SearchContext searchContext = SearchContextFactory.getInstance(request); boolean andOperator = ParamUtil.getBoolean(request, "andOperator"); searchContext.setAndSearch(andOperator); if ((attributes != null) && !attributes.isEmpty()) { searchContext.setAttributes(attributes); } searchContext.setEnd(searchContainer.getEnd()); Class<?> indexerClass = Class.forName(indexer.getClassNames()[0]); if (!GroupedModel.class.isAssignableFrom(indexerClass)) { searchContext.setGroupIds(null); } else if (searchContext.getAttribute(Field.GROUP_ID) != null) { long groupId = GetterUtil.getLong(searchContext.getAttribute(Field.GROUP_ID)); searchContext.setGroupIds(new long[] { groupId }); } if (Validator.isNotNull(keywords)) { searchContext.setKeywords(keywords); } if (ArrayUtil.isNotEmpty(sorts)) { searchContext.setSorts(sorts); } searchContext.setStart(searchContainer.getStart()); Hits hits = indexer.search(searchContext); alloySearchResult.setHits(hits); alloySearchResult.setPortletURL(portletURL, searchContext.getAttributes()); alloySearchResult.afterPropertiesSet(); return alloySearchResult; }
From source file:com.liferay.alloy.mvc.BaseAlloyIndexer.java
License:Open Source License
@Override public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception { int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_ANY); if (status != WorkflowConstants.STATUS_ANY) { contextQuery.addRequiredTerm(Field.STATUS, status); }//from w w w.java 2s . c om }
From source file:com.liferay.asset.categories.internal.search.AssetCategoryIndexer.java
License:Open Source License
@Override public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception { long[] parentCategoryIds = (long[]) searchContext.getAttribute(Field.ASSET_PARENT_CATEGORY_IDS); if (!ArrayUtil.isEmpty(parentCategoryIds)) { TermsFilter parentCategoryTermsFilter = new TermsFilter(Field.ASSET_PARENT_CATEGORY_ID); parentCategoryTermsFilter.addValues(ArrayUtil.toStringArray(parentCategoryIds)); contextBooleanFilter.add(parentCategoryTermsFilter, BooleanClauseOccur.MUST); }//from ww w.j a va2 s . co m long[] vocabularyIds = (long[]) searchContext.getAttribute(Field.ASSET_VOCABULARY_IDS); if (!ArrayUtil.isEmpty(vocabularyIds)) { TermsFilter vocabularyTermsFilter = new TermsFilter(Field.ASSET_VOCABULARY_ID); vocabularyTermsFilter.addValues(ArrayUtil.toStringArray(vocabularyIds)); contextBooleanFilter.add(vocabularyTermsFilter, BooleanClauseOccur.MUST); } }
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); }//ww w .jav a 2 s . c o m }
From source file:com.liferay.asset.categories.internal.search.AssetVocabularyIndexer.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(); addSearchLocalizedTerm(localizedQuery, searchContext, Field.TITLE, true); searchQuery.add(localizedQuery, BooleanClauseOccur.SHOULD); }/*from ww w . j a v a 2 s .c o m*/ }
From source file:com.liferay.asset.search.test.AssetUtilSearchSortTest.java
License:Open Source License
@Test public void testPriority() throws Exception { double[] priorities = { 10, 1, 40, 5.3 }; for (double priority : priorities) { addJournalArticle(serviceContext -> serviceContext.setAssetPriority(priority)); }/*w w w . j a v a 2 s . c o m*/ SearchContext searchContext = createSearchContext(); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.addSelectedFieldNames(Field.PRIORITY); AssetEntryQuery assetEntryQuery = createAssetEntryQueryOrderBy(Field.PRIORITY); Hits hits = _assetHelper.search(searchContext, assetEntryQuery, QueryUtil.ALL_POS, QueryUtil.ALL_POS); DocumentsAssert.assertValues((String) searchContext.getAttribute("queryString"), hits.getDocs(), Field.PRIORITY, Arrays.asList("1.0", "5.3", "10.0", "40.0")); }
From source file:com.liferay.asset.tags.internal.search.AssetTagIndexer.java
License:Open Source License
@Override public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter, SearchContext searchContext) throws Exception { String name = (String) searchContext.getAttribute(Field.NAME); if (Validator.isNotNull(name)) { BooleanQuery nameQuery = new BooleanQueryImpl(); addSearchTerm(nameQuery, searchContext, Field.NAME, true); searchQuery.add(nameQuery, BooleanClauseOccur.SHOULD); }/*from w w w. j av a2 s.c om*/ }
From source file:com.liferay.dynamic.data.lists.internal.search.DDLRecordIndexer.java
License:Open Source License
@Override public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception { int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED); if (status != WorkflowConstants.STATUS_ANY) { contextBooleanFilter.addRequiredTerm(Field.STATUS, status); }//from w w w .j a va 2 s . com long recordSetId = GetterUtil.getLong(searchContext.getAttribute("recordSetId")); if (recordSetId > 0) { contextBooleanFilter.addRequiredTerm("recordSetId", recordSetId); } long recordSetScope = GetterUtil.getLong(searchContext.getAttribute("recordSetScope"), DDLRecordSetConstants.SCOPE_DYNAMIC_DATA_LISTS); contextBooleanFilter.addRequiredTerm("recordSetScope", recordSetScope); addSearchClassTypeIds(contextBooleanFilter, searchContext); String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName"); Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue"); if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) { QueryFilter queryFilter = ddmIndexer.createFieldValueQueryFilter(ddmStructureFieldName, ddmStructureFieldValue, searchContext.getLocale()); contextBooleanFilter.add(queryFilter, BooleanClauseOccur.MUST); } }
From source file:com.liferay.dynamic.data.mapping.internal.search.DDMFormInstanceRecordIndexer.java
License:Open Source License
@Override public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception { int status = GetterUtil.getInteger(searchContext.getAttribute(Field.STATUS), WorkflowConstants.STATUS_APPROVED); if (status != WorkflowConstants.STATUS_ANY) { contextBooleanFilter.addRequiredTerm(Field.STATUS, status); }// ww w . j av a 2s . c om long ddmFormInstanceId = GetterUtil.getLong(searchContext.getAttribute("ddmFormInstanceId")); if (ddmFormInstanceId > 0) { contextBooleanFilter.addRequiredTerm("ddmFormInstanceId", ddmFormInstanceId); } addSearchClassTypeIds(contextBooleanFilter, searchContext); String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName"); Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue"); if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) { QueryFilter queryFilter = ddmIndexer.createFieldValueQueryFilter(ddmStructureFieldName, ddmStructureFieldValue, searchContext.getLocale()); contextBooleanFilter.add(queryFilter, BooleanClauseOccur.MUST); } }
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)); }/*from www .jav a2 s. c om*/ }