List of usage examples for com.liferay.portal.kernel.search Hits getDocs
public Document[] getDocs();
From source file:com.bemis.portal.customer.service.impl.CustomerProfileLocalServiceImpl.java
License:Open Source License
@Override public List<CustomerProfile> searchCustomer(String criteria, int start, int end) throws PortalException { long companyId = _bemisPortalService.getDefaultCompanyId(); List<CustomerProfile> customerProfiles = new ArrayList<>(); LinkedHashMap<String, Object> params = new LinkedHashMap<>(); params.put(_EXPANDO_ATTRIBUTES, criteria); Hits hits = _organizationLocalService.search(companyId, OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, criteria, params, start, end, null); Document[] documents = hits.getDocs(); for (Document doc : documents) { long orgId = GetterUtil.getLong(doc.get(Field.ORGANIZATION_ID)); Organization org = _organizationLocalService.getOrganization(orgId); customerProfiles.add(asCustomerProfile(org)); }//from w ww . ja va2 s . c om return customerProfiles; }
From source file:com.cd.learning.hook.MBUtil.java
License:Open Source License
public static List<Object> getEntries(Hits hits) { List<Object> entries = new ArrayList<Object>(); for (Document document : hits.getDocs()) { long categoryId = GetterUtil.getLong(document.get(Field.CATEGORY_ID)); try {/*from w ww . j a v a 2 s . c o m*/ MBCategoryLocalServiceUtil.getCategory(categoryId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "category " + categoryId); } continue; } long threadId = GetterUtil.getLong(document.get("threadId")); try { MBThreadLocalServiceUtil.getThread(threadId); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "thread " + threadId); } continue; } String entryClassName = document.get(Field.ENTRY_CLASS_NAME); long entryClassPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); Object obj = null; try { if (entryClassName.equals(DLFileEntry.class.getName())) { long classPK = GetterUtil.getLong(document.get(Field.CLASS_PK)); MBMessageLocalServiceUtil.getMessage(classPK); obj = DLFileEntryLocalServiceUtil.getDLFileEntry(entryClassPK); } else if (entryClassName.equals(MBMessage.class.getName())) { obj = MBMessageLocalServiceUtil.getMessage(entryClassPK); } entries.add(obj); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Message boards search index is stale and contains " + "entry {className=" + entryClassName + ", " + "classPK=" + entryClassPK + "}"); } continue; } } return entries; }
From source file:com.ext.portlet.Activity.ActivityUtil.java
License:Open Source License
private static List<SocialActivity> retrieveAggregatedSocialActivities(Hits hits) { List<SocialActivity> aggregatedSocialActivities = new ArrayList<>(hits.getLength()); for (Document activityDoc : hits.getDocs()) { try {//from ww w . j a v a 2 s. c o m SocialActivity sa = SocialActivityLocalServiceUtil .getSocialActivity(GetterUtil.getLong(activityDoc.getField("activityId").getValue())); aggregatedSocialActivities.add(sa); } catch (Exception e) { _log.error(e); } } return aggregatedSocialActivities; }
From source file:com.idetronic.eprint.service.impl.EprintLocalServiceImpl.java
License:Open Source License
public List<Eprint> searchIndex(String keyword, long companyId, long groupId) throws SystemException { Hits hits = getHits(keyword, companyId, groupId); // 1. return null if no results if (Validator.isNull(hits) || hits.getLength() == 0) return null; List<Eprint> eprints = new ArrayList<Eprint>(); for (Document document : hits.getDocs()) { long eprintId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); Eprint eprint = fetchEprint(eprintId); eprints.add(eprint);// w w w . j a va 2 s .c o m } return eprints; }
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; try {/*from w w w . j a v a 2 s .co m*/ 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 w w .j a v a 2 s . c o m*/ 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; try {// w ww . j a va 2 s . c o m 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; }
From source file:com.liferay.alloy.mvc.BaseAlloyControllerImpl.java
License:Open Source License
protected void setJSONResponseContent(AlloySearchResult alloySearchResult) throws Exception { Hits hits = alloySearchResult.getHits(); Document[] documents = hits.getDocs(); setJSONResponseContent(documents);//w ww.j av a2 s.com }
From source file:com.liferay.asset.internal.util.AssetHelperImpl.java
License:Open Source License
@Override public List<AssetEntry> getAssetEntries(Hits hits) { if (hits.getDocs() == null) { return Collections.emptyList(); }/*from w ww .j a v a2s .c om*/ List<AssetEntry> assetEntries = new ArrayList<>(); for (Document document : hits.getDocs()) { String className = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME)); long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(className, classPK); if (assetEntry != null) { assetEntries.add(assetEntry); } } return assetEntries; }
From source file:com.liferay.asset.search.test.AssetSearcherStagingTest.java
License:Open Source License
@Test public void testSiteRolePermissions() throws Exception { Role role = addRole(RoleConstants.TYPE_SITE); String className = "com.liferay.journal.model.JournalArticle"; RoleTestUtil.addResourcePermission(role, className, ResourceConstants.SCOPE_GROUP_TEMPLATE, "0", ActionKeys.VIEW);/*w w w . jav a 2 s.c om*/ User user = addUser(); ServiceTestUtil.setUser(user); addUserGroupRole(user, role); addJournalArticle(); GroupTestUtil.enableLocalStaging(_group); SearchContext searchContext = getSearchContext(); Group stagingGroup = _group.getStagingGroup(); searchContext.setGroupIds(new long[] { stagingGroup.getGroupId() }); searchContext.setUserId(user.getUserId()); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.addSelectedFieldNames(Field.GROUP_ID, Field.STAGING_GROUP); AssetEntryQuery assetEntryQuery = getAssetEntryQuery(className); Hits hits = search(assetEntryQuery, searchContext); Document[] documents = hits.getDocs(); DocumentsAssert.assertCount(hits.toString(), documents, Field.COMPANY_ID, 1); Document document = documents[0]; assertField(document, Field.GROUP_ID, String.valueOf(stagingGroup.getGroupId())); assertField(document, Field.STAGING_GROUP, StringPool.TRUE); }