List of usage examples for com.liferay.portal.kernel.search Field ENTRY_CLASS_NAME
String ENTRY_CLASS_NAME
To view the source code for com.liferay.portal.kernel.search Field ENTRY_CLASS_NAME.
Click Source Link
From source file:org.xcolab.portlets.search.Indexer.java
License:Open Source License
public static Document getArticleDocument(long companyId, long groupId, String articleId, double version, String title, String description, String content, String type, Date displayDate, String[] tagsCategories, String[] tagsEntries, ExpandoBridge expandoBridge) { if ((content != null) && ((content.indexOf("<dynamic-content") != -1) || (content.indexOf("<static-content") != -1))) { content = _getIndexableContent(content); content = StringUtil.replace(content, "<![CDATA[", StringPool.BLANK); content = StringUtil.replace(content, "]]>", StringPool.BLANK); }//from w ww . ja v a 2 s. c o m content = StringUtil.replace(content, "&", "&"); content = StringUtil.replace(content, "<", "<"); content = StringUtil.replace(content, ">", ">"); content = HtmlUtil.extractText(content); Document doc = new DocumentImpl(); // check if this is an most recent version of an article JournalArticle article; boolean isOld = false; try { article = JournalArticleLocalServiceUtil.getArticle(groupId, articleId); if (article.getVersion() != version) { isOld = true; } } catch (Exception e1) { e1.printStackTrace(); // ignore } if (isOld) { doc.addUID(PORTLET_ID, articleId, "old"); } else { doc.addUID(PORTLET_ID, articleId); } doc.addModifiedDate(displayDate); doc.addKeyword(Field.COMPANY_ID, companyId); doc.addKeyword(Field.PORTLET_ID, PORTLET_ID); doc.addKeyword(Field.GROUP_ID, groupId); doc.addText(Field.TITLE, title); doc.addText(Field.CONTENT, content); doc.addText(Field.DESCRIPTION, description); doc.addKeyword(Field.ENTRY_CLASS_PK, articleId); doc.addKeyword(Field.VERSION, version); doc.addKeyword(Field.TYPE, type); ExpandoBridgeIndexerUtil.addAttributes(doc, expandoBridge); try { Layout pageLayout = getLayoutForContent(articleId); if (pageLayout != null) { Layout tmp = pageLayout; boolean isAbout = false; while (tmp != null && !isAbout) { if (tmp.getFriendlyURL().toLowerCase().contains("/about") || tmp.getFriendlyURL().toLowerCase().contains("/contests")) { isAbout = true; } if (tmp.getParentLayoutId() > 0) { try { tmp = LayoutLocalServiceUtil.getLayout(tmp.getGroupId(), tmp.getPrivateLayout(), tmp.getParentLayoutId()); } catch (com.liferay.portal.NoSuchLayoutException e) { tmp = null; } catch (PortalException e) { tmp = null; } } else { tmp = null; } } if (isAbout) { doc.addKeyword("PAGE_URL", pageLayout.getFriendlyURL()); doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName() + ".index"); } } else { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); } } catch (SystemException e) { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); e.printStackTrace(); } return doc; }
From source file:org.xcolab.portlets.search.Indexer.java
License:Open Source License
@Override public Document getDocument(Object obj) throws SearchException { JournalArticle article = (JournalArticle) obj; String articleId = article.getArticleId(); long groupId = article.getGroupId(); long companyId = article.getCompanyId(); double version = article.getVersion(); String content = article.getContent(); String title = article.getTitle(); Date displayDate = article.getDisplayDate(); String description = article.getDescription(); String type = article.getType(); ExpandoBridge expandoBridge = article.getExpandoBridge(); if ((content != null) && ((content.indexOf("<dynamic-content") != -1) || (content.indexOf("<static-content") != -1))) { content = _getIndexableContent(content); content = StringUtil.replace(content, "<![CDATA[", StringPool.BLANK); content = StringUtil.replace(content, "]]>", StringPool.BLANK); }/*from w w w . ja v a2 s . com*/ content = StringUtil.replace(content, "&", "&"); content = StringUtil.replace(content, "<", "<"); content = StringUtil.replace(content, ">", ">"); content = HtmlUtil.extractText(content); Document doc = new DocumentImpl(); // check if this is an most recent version of an article boolean isOld = false; try { JournalArticle tmpArticle = JournalArticleLocalServiceUtil.getArticle(groupId, String.valueOf(articleId)); if (article.getVersion() != version) { isOld = true; } } catch (Exception e1) { e1.printStackTrace(); // ignore } if (isOld) { doc.addUID(PORTLET_ID, articleId, "old"); } else { doc.addUID(PORTLET_ID, articleId); } doc.addModifiedDate(displayDate); doc.addKeyword(Field.COMPANY_ID, companyId); doc.addKeyword(Field.PORTLET_ID, PORTLET_ID); doc.addKeyword(Field.GROUP_ID, groupId); doc.addText(Field.TITLE, title); doc.addText(Field.CONTENT, content); doc.addText(Field.DESCRIPTION, description); doc.addKeyword(Field.ENTRY_CLASS_PK, articleId); doc.addKeyword(Field.VERSION, version); doc.addKeyword(Field.TYPE, type); ExpandoBridgeIndexerUtil.addAttributes(doc, expandoBridge); try { Layout pageLayout = getLayoutForContent(articleId); if (pageLayout != null) { Layout tmp = pageLayout; boolean isAbout = false; while (tmp != null && !isAbout) { if (tmp.getFriendlyURL().toLowerCase().contains("/about") || tmp.getFriendlyURL().toLowerCase().contains("/contests")) { isAbout = true; } if (tmp.getParentLayoutId() > 0) { try { tmp = LayoutLocalServiceUtil.getLayout(tmp.getGroupId(), tmp.getPrivateLayout(), tmp.getParentLayoutId()); } catch (com.liferay.portal.NoSuchLayoutException e) { tmp = null; } catch (PortalException e) { tmp = null; } } else { tmp = null; } } if (isAbout) { doc.addKeyword("PAGE_URL", pageLayout.getFriendlyURL()); doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName() + ".index"); } } else { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); } } catch (SystemException e) { doc.addKeyword(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); e.printStackTrace(); } return doc; }
From source file:vn.com.ecopharma.emp.service.impl.EmpAnnualLeaveLocalServiceImpl.java
License:Open Source License
public List<Document> searchAllDocuments(SearchContext searchContext, List<Query> filterQueries, long companyId, Sort sort, int start, int end) { LOGGER.info("FilterQueries size: " + filterQueries.size()); final BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); final BooleanQuery allEntriesBooleanQuery = BooleanQueryFactoryUtil.create(searchContext); allEntriesBooleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, EmpAnnualLeave.class.getName()); try {/*from w w w. j a v a2s . c o m*/ // add filter queries fullQuery.add(allEntriesBooleanQuery, BooleanClauseOccur.MUST); if (filterQueries != null && filterQueries.size() > 0) { for (Query query : filterQueries) { fullQuery.add(query, BooleanClauseOccur.MUST); } } final List<Document> documents = SearchEngineUtil .search(SearchEngineUtil.getDefaultSearchEngineId(), companyId, fullQuery, sort, start, end) .toList(); LOGGER.info("RESULT SIZE: " + documents.size()); return documents; } catch (SearchException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } catch (ParseException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } return new ArrayList<>(); }
From source file:vn.com.ecopharma.emp.service.impl.EmpAnnualLeaveLocalServiceImpl.java
License:Open Source License
public Document getIndexedDocument(long id, SearchContext searchContext) { searchContext.setPortletIds(new String[] { EMInfo.PORTLET_ID }); BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext); booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, EmpAnnualLeave.class.getName()); booleanQuery.addExactTerm(EmpAnnualLeaveField.ID, id); try {/*from ww w. j a va 2 s . c o m*/ fullQuery.add(booleanQuery, BooleanClauseOccur.MUST); Hits hits = SearchEngineUtil.search(searchContext, fullQuery); return !hits.toList().isEmpty() ? hits.toList().get(0) : null; } catch (ParseException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } catch (SearchException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } return null; }
From source file:vn.com.ecopharma.emp.service.impl.EmpAnnualLeaveLocalServiceImpl.java
License:Open Source License
public void removeAllIndexes(SearchContext searchContext, long companyId) { final BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext); booleanQuery.addExactTerm(Field.ENTRY_CLASS_NAME, EmpAnnualLeave.class.getName()); try {//www .j av a 2 s. co m final Hits hits = SearchEngineUtil.search(SearchEngineUtil.getDefaultSearchEngineId(), companyId, booleanQuery, QueryUtil.ALL_POS, QueryUtil.ALL_POS); final List<Document> docs = hits.toList(); for (Document doc : docs) { LOGGER.info("DELETE EmpAnnualLeave Index UID: " + doc.getUID()); SearchEngineUtil.deleteDocument(SearchEngineUtil.getDefaultSearchEngineId(), companyId, doc.getUID()); } } catch (SearchException e) { e.printStackTrace(); } }
From source file:vn.com.ecopharma.emp.service.impl.EmpDisciplineLocalServiceImpl.java
License:Open Source License
public List<Document> searchAllDocuments(SearchContext searchContext, List<Query> filterQueries, long companyId, Sort sort, int start, int end) { LOGGER.info("FilterQueries size: " + filterQueries.size()); final BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); final BooleanQuery allEntriesBooleanQuery = BooleanQueryFactoryUtil.create(searchContext); allEntriesBooleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, EmpDiscipline.class.getName()); try {//from w w w .ja va2s .c om // add filter queries fullQuery.add(allEntriesBooleanQuery, BooleanClauseOccur.MUST); if (filterQueries != null && filterQueries.size() > 0) { for (Query query : filterQueries) { fullQuery.add(query, BooleanClauseOccur.MUST); } } final List<Document> documents = SearchEngineUtil .search(SearchEngineUtil.getDefaultSearchEngineId(), companyId, fullQuery, sort, start, end) .toList(); LOGGER.info("RESULT SIZE: " + documents.size()); return documents; } catch (SearchException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } catch (ParseException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } return new ArrayList<>(); }
From source file:vn.com.ecopharma.emp.service.impl.EmpDisciplineLocalServiceImpl.java
License:Open Source License
public Document getIndexedDocument(long id, SearchContext searchContext) { searchContext.setPortletIds(new String[] { EMInfo.PORTLET_ID }); BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext); booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, EmpDiscipline.class.getName()); booleanQuery.addExactTerm(EmpDisciplineField.ID, id); try {/* w w w . j a v a 2 s. co m*/ fullQuery.add(booleanQuery, BooleanClauseOccur.MUST); Hits hits = SearchEngineUtil.search(searchContext, fullQuery); return !hits.toList().isEmpty() ? hits.toList().get(0) : null; } catch (ParseException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } catch (SearchException e) { LogFactoryUtil.getLog(EmpDisciplineLocalServiceImpl.class).info(e); } return null; }
From source file:vn.com.ecopharma.emp.service.impl.EmpLocalServiceImpl.java
License:Open Source License
@Override public List<Document> searchAllUnDeletedEmpIndexedDocument(SearchContext searchContext, List<Query> filterQueries, long companyId, Sort sort, int start, int end) { final BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); final BooleanQuery allEmpEntriesBooleanQuery = BooleanQueryFactoryUtil.create(searchContext); final BooleanQuery noneDeletedEmpsBooleanQuery = BooleanQueryFactoryUtil.create(searchContext); allEmpEntriesBooleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, Emp.class.getName()); noneDeletedEmpsBooleanQuery.addExactTerm(EmpField.IS_DELETED, "false"); try {// w ww . j a va 2s . c o m // add filter queries fullQuery.add(allEmpEntriesBooleanQuery, BooleanClauseOccur.MUST); if (filterQueries != null && !filterQueries.isEmpty()) { for (Query query : filterQueries) { fullQuery.add(query, BooleanClauseOccur.MUST); } } // always filter for none-delete item fullQuery.add(noneDeletedEmpsBooleanQuery, BooleanClauseOccur.MUST); LOGGER.info(fullQuery); final List<Document> documents = SearchEngineUtil .search(SearchEngineUtil.getDefaultSearchEngineId(), companyId, fullQuery, sort, start, end) .toList(); LOGGER.info("RESULT SIZE: " + documents.size()); return documents; } catch (SearchException e) { LOGGER.info(e); } catch (ParseException e) { LOGGER.info(e); } return new ArrayList<>(); }
From source file:vn.com.ecopharma.emp.service.impl.EmpLocalServiceImpl.java
License:Open Source License
@Override public Document getIndexedEmp(long employeeId, SearchContext searchContext) { searchContext.setPortletIds(new String[] { EMInfo.PORTLET_ID }); BooleanQuery fullQuery = BooleanQueryFactoryUtil.create(searchContext); BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext); booleanQuery.addRequiredTerm(Field.ENTRY_CLASS_NAME, Emp.class.getName()); booleanQuery.addExactTerm(EmpField.EMP_ID, employeeId); try {//w w w. ja v a2 s. c o m fullQuery.add(booleanQuery, BooleanClauseOccur.MUST); Hits hits = SearchEngineUtil.search(searchContext, fullQuery); return !hits.toList().isEmpty() ? hits.toList().get(0) : null; } catch (ParseException e) { LOGGER.info(e); } catch (SearchException e) { LOGGER.info(e); } return null; }
From source file:vn.com.ecopharma.emp.service.impl.EmpLocalServiceImpl.java
License:Open Source License
@Override public void removeAllEmpIndexes(SearchContext searchContext, long companyId) { final BooleanQuery booleanQuery = BooleanQueryFactoryUtil.create(searchContext); booleanQuery.addExactTerm(Field.ENTRY_CLASS_NAME, Emp.class.getName()); try {//w w w . j av a 2s.c o m final Hits hits = SearchEngineUtil.search(SearchEngineUtil.getDefaultSearchEngineId(), companyId, booleanQuery, QueryUtil.ALL_POS, QueryUtil.ALL_POS); final List<Document> docs = hits.toList(); for (Document doc : docs) { SearchEngineUtil.deleteDocument(SearchEngineUtil.getDefaultSearchEngineId(), companyId, doc.getUID()); } } catch (SearchException e) { LOGGER.info(e); } }