`
hu437
  • 浏览: 193183 次
  • 性别: Icon_minigender_1
  • 来自: 昆明
社区版块
存档分类
最新评论

增强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,重新运行服务器,新的检索即可使用。

分享到:
评论
2 楼 hu437 2011-06-23  
hm2008 写道
你好,想请问下,你那样的话 重启服务器,怎么体现出来你所加的那些,看你那边基本上是文件搜索,是不是再文档portlet的搜索就能够看得见呢?


不明白什么意思,这个是针对liferay 4.2.2的,其他版本可能不适合

这个只是修改了一个liferay里面文章索引的范围和搜索的范围
1 楼 hm2008 2011-06-23  
你好,想请问下,你那样的话 重启服务器,怎么体现出来你所加的那些,看你那边基本上是文件搜索,是不是再文档portlet的搜索就能够看得见呢?

相关推荐

Global site tag (gtag.js) - Google Analytics