List of usage examples for com.liferay.portal.kernel.search SearchContext setKeywords
public void setKeywords(String keywords)
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); }/*w w w.j a v a2 s. c o m*/ 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.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 ava 2 s. co 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 w w w .j av a 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.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); }/*from w w w . j a v a 2 s . c om*/ 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.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.util.test.BookmarksTestUtil.java
License:Open Source License
public static SearchContext getSearchContext(long companyId, long groupId, long folderId, String keywords, boolean highlight, boolean score) { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setFolderIds(new long[] { folderId }); searchContext.setGroupIds(new long[] { groupId }); searchContext.setKeywords(keywords); QueryConfig queryConfig = new QueryConfig(); queryConfig.setHighlightEnabled(highlight); queryConfig.setScoreEnabled(score);//w w w . ja v a 2 s . c o m searchContext.setQueryConfig(queryConfig); 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 w ww .java 2 s . 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.configuration.admin.web.internal.portlet.action.SearchMVCRenderCommand.java
License:Open Source License
@Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException { Indexer indexer = _indexerRegistry.nullSafeGetIndexer(ConfigurationModel.class); SearchContext searchContext = new SearchContext(); searchContext.setAndSearch(false);//from www.ja v a2 s .c o m searchContext.setCompanyId(CompanyConstants.SYSTEM); searchContext.setLocale(renderRequest.getLocale()); String keywords = renderRequest.getParameter("keywords"); if (Validator.isNotNull(keywords)) { searchContext.setKeywords(keywords); } QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setHighlightEnabled(true); queryConfig.setLocale(renderRequest.getLocale()); queryConfig.setScoreEnabled(true); try { Hits hits = indexer.search(searchContext); Document[] documents = hits.getDocs(); Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever .getConfigurationModels(); List<ConfigurationModel> searchResults = new ArrayList<>(documents.length); for (Document document : documents) { String configurationModelId = document.get(FieldNames.CONFIGURATION_MODEL_ID); ConfigurationModel configurationModel = configurationModels.get(configurationModelId); if (configurationModel == null) { String configurationModelFactoryId = document.get(FieldNames.CONFIGURATION_MODEL_FACTORY_PID); configurationModel = configurationModels.get(configurationModelFactoryId); } if (configurationModel != null) { searchResults.add(configurationModel); } } ConfigurationModelIterator configurationModelIterator = new ConfigurationModelIterator(searchResults); renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_MODEL_ITERATOR, configurationModelIterator); renderRequest.setAttribute(ConfigurationAdminWebKeys.RESOURCE_BUNDLE_LOADER_PROVIDER, _resourceBundleLoaderProvider); } catch (Exception e) { throw new PortletException(e); } return "/view.jsp"; }
From source file:com.liferay.content.targeting.service.impl.CampaignLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long groupId, String keywords, int start, int end) throws PortalException, SystemException { SearchContext searchContext = new SearchContext(); Group group = GroupLocalServiceUtil.getGroup(groupId); searchContext.setCompanyId(group.getCompanyId()); searchContext.setEnd(end);//from w ww . j a v a2s. c o m searchContext.setGroupIds(new long[] { groupId }); searchContext.setKeywords(keywords); searchContext.setStart(start); return searchContext; }
From source file:com.liferay.content.targeting.service.impl.UserSegmentLocalServiceImpl.java
License:Open Source License
protected SearchContext buildSearchContext(long groupId, String keywords, int start, int end) throws PortalException, SystemException { SearchContext searchContext = new SearchContext(); Group group = GroupLocalServiceUtil.getGroup(groupId); searchContext.setCompanyId(group.getCompanyId()); searchContext.setEnd(end);/*from w w w.j a v a2 s . co m*/ searchContext.setGroupIds(new long[] { groupId }); searchContext.setKeywords(keywords); searchContext.setStart(start); return searchContext; }