List of usage examples for com.liferay.portal.kernel.search SearchContext setCompanyId
public void setCompanyId(long companyId)
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); }//from ww w .j av a 2 s . c om 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.BibliographyServiceImpl.java
License:Open Source License
/** * @param userId/*from ww w. j av a2s.c om*/ * the userId of the current user * @param groupId * the scopeGroupId of the bibliography. 0 means: any scope. * @param ownerUserId * the userId of the bibliography owner. -1 means: ignore * ownerUserId parameter. * @param keywords * @param start * @param end * @param sort * @return the hits for the given parameters * @since 1.0.0 * @throws PortalException */ public Hits search(long userId, long groupId, long ownerUserId, String keywords, int start, int end, Sort sort) throws PortalException { if (sort == null) { sort = new Sort(Field.MODIFIED_DATE, true); } Indexer<Bibliography> indexer = IndexerRegistryUtil.getIndexer(Bibliography.class.getName()); SearchContext searchContext = new SearchContext(); searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY); searchContext.setAttribute("paginationType", "more"); User user = UserLocalServiceUtil.getUser(userId); searchContext.setCompanyId(user.getCompanyId()); searchContext.setEnd(end); if (groupId > 0) { searchContext.setGroupIds(new long[] { groupId }); } searchContext.setSorts(sort); searchContext.setStart(start); searchContext.setUserId(userId); searchContext.setOwnerUserId(ownerUserId); return indexer.search(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); }// w w w . ja va 2 s . c om 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); }/* w w w.j a v a2s . co m*/ 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.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 w w w. j ava 2 s .c o m*/ 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 ww . j ava 2s . 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.idetronic.eprint.service.impl.EprintLocalServiceImpl.java
License:Open Source License
public Hits getHits(String keyword, long companyId, long groupId) { // 1. Preparing a Search Context SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); String[] CLASS_NAMES = { Eprint.class.getName() }; searchContext.setEntryClassNames(CLASS_NAMES); long[] groupIds = { groupId }; searchContext.setGroupIds(groupIds); // 2. Preparing a Query to search BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); String[] terms = { Field.DESCRIPTION, Field.TITLE }; try {// ww w.j av a 2 s . co m searchQuery.addTerms(terms, keyword); } catch (ParseException e) { e.printStackTrace(); } // 3. Firing the query to get hits Hits hits = null; try { hits = SearchEngineUtil.search(searchContext, searchQuery); } catch (SearchException e) { e.printStackTrace(); } return hits; }
From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public List<LMSBook> AdvanceSearchAny(long companyId, long groupId, String title, String author, String desc) { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEntryClassNames(CLASS_NAMES); BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); Hits hits = null;//from w ww. j a va 2 s . c om try { String[] terms = { Field.TITLE, Field.DESCRIPTION, Field.NAME }; searchQuery.addTerms(terms, getModelClassName()); searchQuery = createQuery(getModelClassName(), getModelClassName(), searchContext, searchQuery); hits = SearchEngineUtil.search(searchContext, searchQuery); } catch (SearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<LMSBook> books = null; if (hits != null && hits.getLength() > 0) { books = new ArrayList<LMSBook>(); for (Document document : hits.getDocs()) { long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK)); try { LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId); books.add(book); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return books; }
From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public List<LMSBook> advanceSearchAll(long companyId, long groupId, String title, String author, String desc, String type) {/* w ww . j a v a2s . c om*/ SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEntryClassNames(CLASS_NAMES); BooleanQuery contextQuery = BooleanQueryFactoryUtil.create(searchContext); contextQuery.addRequiredTerm(Field.COMPANY_ID, companyId); contextQuery.addRequiredTerm(Field.PORTLET_ID, Long.toString(ClassNameLocalServiceUtil.getClassNameId(LMSBook.class))); BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); fullQuery.setQueryConfig(searchContext.getQueryConfig()); try { fullQuery.add(contextQuery, BooleanClauseOccur.MUST); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); Hits hits = null; if (Validator.isNotNull(title)) { Sort sort = new Sort(Field.TITLE, true); searchContext.setSorts(new Sort[] { sort }); fullQuery = createQuery(Field.TITLE, title, searchContext, fullQuery); } if (Validator.isNotNull(author)) { fullQuery = createQuery(Field.NAME, author, searchContext, fullQuery); } if (Validator.isNotNull(desc)) { fullQuery = createQuery(Field.DESCRIPTION, desc, searchContext, fullQuery); } if (searchQuery.clauses().size() > 0) { try { fullQuery.add(searchQuery, BooleanClauseOccur.MUST); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { hits = SearchEngineUtil.search(searchContext, fullQuery); } catch (SearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<LMSBook> books = new ArrayList<LMSBook>(); if (hits != null && hits.getLength() > 0) { for (Document document : hits.getDocs()) { long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK)); try { LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId); books.add(book); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return books; }
From source file:com.library.slayer.service.impl.LMSBookLocalServiceImpl.java
License:Open Source License
public List<LMSBook> searchBooks(long companyId, String keywords) { SearchContext searchContext = new SearchContext(); searchContext.setCompanyId(companyId); searchContext.setEntryClassNames(CLASS_NAMES); BooleanQuery searchQuery = BooleanQueryFactoryUtil.create(searchContext); Hits hits = null;/*from w ww.j a v a2 s . com*/ try { String[] terms = { Field.TITLE, Field.DESCRIPTION }; searchQuery.addTerms(terms, keywords); hits = SearchEngineUtil.search(searchContext, searchQuery); } catch (SearchException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<LMSBook> books = null; if (hits != null && hits.getLength() > 0) { books = new ArrayList<LMSBook>(); for (Document document : hits.getDocs()) { long bookId = Long.parseLong(document.get(Field.ENTRY_CLASS_PK)); try { LMSBook book = LMSBookLocalServiceUtil.getLMSBook(bookId); books.add(book); } catch (PortalException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return books; }