List of usage examples for com.liferay.portal.kernel.search Field CATEGORY_ID
String CATEGORY_ID
To view the source code for com.liferay.portal.kernel.search Field CATEGORY_ID.
Click Source Link
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 {/*w w w .j a va 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.liferay.message.boards.internal.search.MBMessageIndexer.java
License:Open Source License
@Override public void addRelatedEntryFields(Document document, Object obj) throws Exception { FileEntry fileEntry = (FileEntry) obj; MBMessage message = MBMessageAttachmentsUtil.fetchMessage(fileEntry.getFileEntryId()); if (message == null) { return;//from w w w .j a va 2 s. c o m } document.addKeyword(Field.CATEGORY_ID, message.getCategoryId()); document.addKeyword("discussion", false); document.addKeyword("threadId", message.getThreadId()); }
From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java
License:Open Source License
@Override public void postProcessContextBooleanFilter(BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception { addStatus(contextBooleanFilter, searchContext); boolean discussion = GetterUtil.getBoolean(searchContext.getAttribute("discussion")); contextBooleanFilter.addRequiredTerm("discussion", discussion); if (searchContext.isIncludeDiscussions()) { addRelatedClassNames(contextBooleanFilter, searchContext); }//from ww w . ja v a 2 s .c o m String classNameId = GetterUtil.getString(searchContext.getAttribute(Field.CLASS_NAME_ID)); if (Validator.isNotNull(classNameId)) { contextBooleanFilter.addRequiredTerm(Field.CLASS_NAME_ID, classNameId); } long threadId = GetterUtil.getLong((String) searchContext.getAttribute("threadId")); if (threadId > 0) { contextBooleanFilter.addRequiredTerm("threadId", threadId); } long[] categoryIds = searchContext.getCategoryIds(); if ((categoryIds != null) && (categoryIds.length > 0) && (categoryIds[0] != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)) { TermsFilter categoriesTermsFilter = new TermsFilter(Field.CATEGORY_ID); for (long categoryId : categoryIds) { try { mbCategoryService.getCategory(categoryId); } catch (PortalException pe) { if (_log.isDebugEnabled()) { _log.debug("Unable to get message boards category " + categoryId, pe); } continue; } categoriesTermsFilter.addValue(String.valueOf(categoryId)); } if (!categoriesTermsFilter.isEmpty()) { contextBooleanFilter.add(categoriesTermsFilter, BooleanClauseOccur.MUST); } } }
From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java
License:Open Source License
@Override protected Document doGetDocument(MBMessage mbMessage) throws Exception { Document document = getBaseModelDocument(CLASS_NAME, mbMessage); document.addKeyword(Field.CATEGORY_ID, mbMessage.getCategoryId()); document.addText(Field.CONTENT, processContent(mbMessage)); document.addKeyword(Field.ROOT_ENTRY_CLASS_PK, mbMessage.getRootMessageId()); document.addText(Field.TITLE, mbMessage.getSubject()); if (mbMessage.isAnonymous()) { document.remove(Field.USER_NAME); }// ww w . j a va 2s .c om MBDiscussion discussion = mbDiscussionLocalService.fetchThreadDiscussion(mbMessage.getThreadId()); if (discussion == null) { document.addKeyword("discussion", false); } else { document.addKeyword("discussion", true); } document.addKeyword("threadId", mbMessage.getThreadId()); if (mbMessage.isDiscussion()) { List<RelatedEntryIndexer> relatedEntryIndexers = RelatedEntryIndexerRegistryUtil .getRelatedEntryIndexers(mbMessage.getClassName()); if (relatedEntryIndexers != null) { for (RelatedEntryIndexer relatedEntryIndexer : relatedEntryIndexers) { Comment comment = commentManager.fetchComment(mbMessage.getMessageId()); if (comment != null) { relatedEntryIndexer.addRelatedEntryFields(document, comment); document.addKeyword(Field.RELATED_ENTRY, true); } } } } return document; }
From source file:com.liferay.portlet.messageboards.util.MBIndexer.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 . j ava 2 s . com*/ boolean discussion = GetterUtil.getBoolean(searchContext.getAttribute("discussion"), false); contextQuery.addRequiredTerm("discussion", discussion); long threadId = GetterUtil.getLong((String) searchContext.getAttribute("threadId")); if (threadId > 0) { contextQuery.addRequiredTerm("threadId", threadId); } long[] categoryIds = searchContext.getCategoryIds(); if ((categoryIds != null) && (categoryIds.length > 0)) { if (categoryIds[0] == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) { return; } BooleanQuery categoriesQuery = BooleanQueryFactoryUtil.create(searchContext); for (long categoryId : categoryIds) { try { MBCategoryServiceUtil.getCategory(categoryId); } catch (Exception e) { continue; } categoriesQuery.addTerm(Field.CATEGORY_ID, categoryId); } contextQuery.add(categoriesQuery, BooleanClauseOccur.MUST); } }
From source file:com.liferay.portlet.messageboards.util.MBIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { MBMessage message = (MBMessage) obj; Document document = getBaseModelDocument(PORTLET_ID, message); document.addKeyword(Field.CATEGORY_ID, message.getCategoryId()); document.addText(Field.CONTENT, processContent(message)); document.addKeyword(Field.ROOT_ENTRY_CLASS_PK, message.getRootMessageId()); document.addText(Field.TITLE, message.getSubject()); if (message.isAnonymous()) { document.remove(Field.USER_NAME); }//w ww . j a v a 2 s. c o m try { MBDiscussionLocalServiceUtil.getThreadDiscussion(message.getThreadId()); document.addKeyword("discussion", true); } catch (NoSuchDiscussionException nsde) { document.addKeyword("discussion", false); } document.addKeyword("threadId", message.getThreadId()); return document; }