增强Liferay的搜索功能

新加入到了公司的门户组,在使用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,重新运行服务器,新的检索即可使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值