全文检索扩展.docx
- 文档编号:23646961
- 上传时间:2023-05-19
- 格式:DOCX
- 页数:13
- 大小:38.05KB
全文检索扩展.docx
《全文检索扩展.docx》由会员分享,可在线阅读,更多相关《全文检索扩展.docx(13页珍藏版)》请在冰豆网上搜索。
全文检索扩展
全文检索扩展
注册全文检索类型
编写java类
编写一个java类,实现IIndexType,这个类必须有以下几个方法:
/**
*获取索引字段
*/
publicList
/**
*获取需要更新的检索类型内容总数量
*@paramlastModifyTime索引最后更新时间
*@paramparams检索内容参数
*@return
*/
publicintgetModifiedTotal(DatelastModifyTime,Mapx
/**
*获取需要更新的检索类型分页内容
*/
publicList
/**
*获取需要删除的检索类型内容总数量
*@paramlastModifyTime索引最后更新时间
*@return
*/
publicintgetDeletedTotal(DatelastModifyTime,Mapx
/**
*获取需要删除的检索类型分页内容
*@paramlastModifyTime索引最后更新时间
*@parampageSize分页大小
*@parampageIndex当前页数
*@return
*/
publicList
索引类型java类也可以直接继承AbstractIndexType抽象类,这个类的getFields()方法提供了检索比较通用的基础字段,如IndexType,Title,ID,_KeyWord,AddTime等。
AbstractIndexType.java类代码完整示例如下:
packagecom.zving.search.service;
importjava.util.ArrayList;
importjava.util.List;
importorg.apache.lucene.document.Field;
publicabstractclassAbstractIndexTypeimplementsIIndexType{
publicList
List
list.add(newField("INDEXTYPE","",Field.Store.YES,Field.Index.NOT_ANALYZED));//索引类型
list.add(newField("TITLE","",Field.Store.YES,Field.Index.ANALYZED));
list.add(newField("CONTENT","",Field.Store.YES,Field.Index.ANALYZED));
list.add(newField("URL","",Field.Store.YES,Field.Index.NO));//可能需要处理
list.add(newField("_KEYWORD","",Field.Store.NO,Field.Index.ANALYZED));//需要自定义内容,一般是Title+Content
list.add(newField("ID","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("ADDTIME","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("MODIFYTIME","",Field.Store.YES,Field.Index.NOT_ANALYZED));
returnlist;
}
}
完整的示例java类代码如下:
packagecom.zving.indextypetest.impl;
importjava.util.ArrayList;
importjava.util.Date;
importjava.util.List;
importorg.apache.lucene.document.Document;
importorg.apache.lucene.document.Field;
importcom.zving.contentcore.properties.impl.IndexEnable;
importcom.zving.contentcore.util.CatalogUtil;
importcom.zving.framework.collection.Mapx;
importcom.zving.framework.data.DataRow;
importcom.zving.framework.data.DataTable;
importcom.zving.framework.data.Q;
importcom.zving.framework.orm.DAO;
importcom.zving.framework.orm.DAOSet;
importcom.zving.framework.utility.DateUtil;
importcom.zving.framework.utility.ObjectUtil;
importcom.zving.framework.utility.StringUtil;
importcom.zving.platform.code.YesOrNo;
importcom.zving.schema.ZCCatalog;
importcom.zving.schema.ZCComment;
importcom.zving.search.service.IIndexType;
publicclassMyTestIndexTypeimplementsIIndexType{
publicstaticfinalStringID="CommentIndexType";//评论索引类型
publicStringgetID(){
returnID;
}
publicStringgetName(){
return"评论索引类型";
}
publicList
List
list.add(newField("INDEXTYPE","",Field.Store.YES,Field.Index.NOT_ANALYZED));//索引类型
list.add(newField("ID","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("TITLE","",Field.Store.YES,Field.Index.ANALYZED));
list.add(newField("CONTENT","",Field.Store.YES,Field.Index.ANALYZED));
list.add(newField("_KEYWORD","",Field.Store.NO,Field.Index.ANALYZED));//需要自定义内容,一般是Title+Content
list.add(newField("SITEID","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("RELACONTENTID","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("CATALOGID","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("CATALOGNAME","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("CATALOGTYPE","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("CATALOGINNERCODE","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("VERIFYFLAG","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("VERIFYUSER","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("VERIFYTIME","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("INDEXENABLE","",Field.Store.YES,Field.Index.NOT_ANALYZED));//栏目配置:
是否开启检索
list.add(newField("ADDTIME","",Field.Store.YES,Field.Index.NOT_ANALYZED));
list.add(newField("MODIFYTIME","",Field.Store.YES,Field.Index.NOT_ANALYZED));
returnlist;
}
publicintgetModifiedTotal(DatelastModifyTime,Mapx
if(ObjectUtil.notEmpty(params.getDate("LastModifyTime"))){
lastModifyTime=params.getDate("LastModifyTime");
}
Qqb=newQ("selectcount(*)fromZCCommentwhereVerifyFlag=?
and(ModifyTime>?
orAddTime>?
)",YesOrNo.Yes,lastModifyTime,
lastModifyTime);
if(ObjectUtil.notEmpty(params.getLong("SiteID"))){
qb.append("andSiteID=?
",params.getLong("SiteID"));
}
if(ObjectUtil.notEmpty(params.getLong("CatalogID"))){
qb.append("andCatalogID=?
",params.getLong("CatalogID"));
}
returnqb.executeInt();
}
publicList
if(ObjectUtil.notEmpty(params.getDate("LastModifyTime"))){
lastModifyTime=params.getDate("LastModifyTime");
}
Qqb=newQ("whereVerifyFlag=?
and(ModifyTime>?
orAddTime>?
)",YesOrNo.Yes,lastModifyTime,lastModifyTime);
if(ObjectUtil.notEmpty(params.getLong("SiteID"))){
qb.append("andSiteID=?
",params.getLong("SiteID"));
}
if(ObjectUtil.notEmpty(params.getLong("CatalogID"))){
qb.append("andCatalogID=?
",params.getLong("CatalogID"));
}
DAOSet
returnparseDocument(set);
}
publicintgetDeletedTotal(DatelastModifyTime,Mapx
Qqb=newQ("selectcount(*)fromBZCCommentwhereBackupMemo=?
andBackupTime>?
",DAO.MEMO_DELETE,lastModifyTime);
if(ObjectUtil.notEmpty(params.getLong("SiteID"))){
qb.append("andSiteID=?
",params.getLong("SiteID"));
}
if(ObjectUtil.notEmpty(params.getLong("CatalogID"))){
qb.append("andCatalogID=?
",params.getLong("CatalogID"));
}
intcount=qb.executeInt();
returncount;
}
publicList
ArrayList
Qqb=newQ("selectIDfromBZCCommentwhereBackupMemo=?
andBackupTime>?
",DAO.MEMO_DELETE,lastModifyTime);
if(ObjectUtil.notEmpty(params.getLong("SiteID"))){
qb.append("andSiteID=?
",params.getLong("SiteID"));
}
if(ObjectUtil.notEmpty(params.getLong("CatalogID"))){
qb.append("andCatalogID=?
",params.getLong("CatalogID"));
}
DataTabledt=qb.fetch(pageSize,pageIndex);
for(DataRowdr:
dt){
list.add(dr.getLong("ID"));
}
returnlist;
}
publicList
List
for(ZCCommentc:
set){
Documentdoc=getDocument(c);
if(doc!
=null&&doc.getFields()!
=null&&doc.getFields().size()>0){
docs.add(getDocument(c));
}
}
returndocs;
}
publicDocumentgetDocument(ZCCommentc){
List
Documentdoc=newDocument();
ZCCatalogcatalog=CatalogUtil.getDAO(c.getCatalogID());
for(Fieldfield:
fields){
if(StringUtil.isNotNull(field.stringValue())){
doc.add(field);
continue;
}
if("INDEXTYPE".equals(field.name())){
field.setValue(ID);//检索类型
}elseif("ID".equals(field.name())){
field.setValue(String.valueOf(c.getID()));
}elseif("TITLE".equals(field.name())){
field.setValue(c.getTitle()==null?
"":
c.getTitle());
}elseif("CONTENT".equals(field.name())){
field.setValue(c.getContent()==null?
"":
c.getContent());
}elseif("_KEYWORD".equals(field.name())){
Stringkeyword=c.getContent()==null?
"":
c.getContent()+"";
keyword+=c.getTitle()==null?
"":
c.getTitle();
field.setValue(keyword);
}elseif("SITEID".equals(field.name())){
field.setValue(String.valueOf(c.getSiteID()));
}elseif("RELACONTENTID".equals(field.name())){
field.setValue(String.valueOf(c.getRelaID()));
}elseif("CATALOGID".equals(field.name())){
field.setValue(String.valueOf(c.getCatalogID()));
}elseif("CATALOGINNERCODE".equals(field.name())){
field.setValue(c.getCatalogInnerCode());
}elseif("CATALOGTYPE".equals(field.name())){
field.setValue(c.getCatalogType());
}elseif("CATALOGNAME".equals(field.name())){
field.setValue(catalog.getName());
}elseif("INDEXENABLE".equals(field.name())){
if(catalog!
=null){
field.setValue(IndexEnable.getValue(catalog.getConfigProps())?
YesOrNo.Yes:
YesOrNo.No);
}else{
field.setValue(YesOrNo.Yes);
}
}elseif("VERIFYFLAG".equals(field.name())){
field.setValue(c.getVerifyFlag());
}elseif("VERIFYUSER".equals(field.name())){
field.setValue(c.getVerifyUser());
}elseif("VERIFYTIME".equals(field.name())){
field.setValue(ObjectUtil.empty(c.getVerifyTime())?
"":
DateUtil.toDateTimeString(c.getVerifyTime()));
}elseif("ADDTIME".equals(field.name())){
field.setValue(ObjectUtil.empty(c.getAddTime())?
"":
DateUtil.toDateTimeString(c.getAddTime()));
}elseif("MODIFYTIME".equals(field.name())){
field.setValue(ObjectUtil.empty(c.getModifyTime())?
"":
DateUtil.toDateTimeString(c.getModifyTime()));
}
doc.add(field);
}
returndoc;
}
}
注册检索类型扩展项
向全文检索类型扩展服务SearchService注册检索类型扩展项
创建索引
启动应用,系统定时任务IndexTask会定时调用SingleIndexer的start()方法创建索引。
按条件搜索
生成的索引通过统一查询入口SearchService获取数据。
实现步骤如下:
1、获取索引参数2、获取搜索器3、返回搜索结果。
获取数据的示例代码如下:
publicDataTablegetSearchList(DataGridActiondga){
/*
*准备索引参数
*/
ArrayList
//按字段条件查询
sps.add(newSearchParam("INDEXTYPE",MyTestIndexType.ID,SearchParam.S
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 全文 检索 扩展