新加入到了公司的门户组,在使用LifeRay的搜索,检索新闻时只能通过标题和正文来检索,现在需要对其进行扩展,让其支持摘要、新闻采编者、新闻原作者等的检索。
修改方法如下:
LifeRay版本:4.2.2(公司的项目,前期采用的这个版本,修改太多,难以升级了~)
涉及修改的类:
com.liferay.portal.lucene.LuceneFields
com.liferay.portlet.journal.util.Indexer
com.liferay.portlet.journal.service.impl.JournalArticleServiceImpl
com.liferay.portal.service.impl.CompanyLocalServiceImpl
建立索引
首先在com.liferay.portlet.journal.util.Indexer类addArticle()方法中可以看到,Liferay索引了哪些字段,从中不难看出Liferay索引了标题、正文和摘要
doc.add(LuceneFields.getText(LuceneFields.TITLE, title));
doc.add(LuceneFields.getText(LuceneFields.CONTENT, content));
doc.add(LuceneFields.getText(LuceneFields.DESCRIPTION, description));
我们新增采编者,原作者的索引
doc.add(LuceneFields.getText(LuceneFields.USER_NAME, userName));
doc.add(LuceneFields.getText(LuceneFields.AUTHOR_SHIP, authorShip));
同时需要在LuceneFields中增相应的字段,这里不再具体写。
方法中的userName和authorShip在方法addArticle()中新增相应的引用即可,同时在com.liferay.portlet.journal.service.impl.JournalArticleServiceImpl类中新增相应的参数(根据Eclipse的错误提示修改即可)
修改检索内容
找到com.liferay.portal.service.impl.CompanyLocalServiceImpl中的public Hits search(String companyId,String portletId, String groupId, String type, String keywords)方法
可以看到这里在检索是只检索了标题和正文
LuceneUtil.addTerm(searchQuery, LuceneFields.TITLE, keywords);
LuceneUtil.addTerm(searchQuery, LuceneFields.CONTENT, keywords);
在这里加入我们需要检索的采编者、原作者、摘要
LuceneUtil.addTerm(searchQuery, LuceneFields.USER_NAME, keywords);
LuceneUtil.addTerm(searchQuery, LuceneFields.AUTHOR_SHIP, keywords);
LuceneUtil.addTerm(searchQuery, LuceneFields.DESCRIPTION, keywords);
到此就修改完成,在portal-ejb下面执行ant deploy,重新运行服务器,新的检索即可使用。