hibernate search索引的问题

xietingyan 2012-12-08 01:33:58
小弟有个问题请教一下
有一个HtmlMaterialBean,有一个ColumnNodeBean,他们的关系
@Indexed(index="htmlMaterialBean")
public class HtmlMaterialBean {
@DocumentId
private String htmlId;
@Field(name="title",store=Store.NO,index=Index.TOKENIZED, analyzer = @Analyzer(impl=ChineseAnalyzer.class))
private String title;
@Field(name="htmlCode",store=Store.NO,index=Index.TOKENIZED, analyzer = @Analyzer(impl=ChineseAnalyzer.class))
private String htmlCode;
private ColumnNodeBean columnNodeBean;
其他代码省略......
}

public class ColumnNodeBean{
private String nodeId;
private String nodeName;
}

<class name="material.bean.HtmlMaterialBean" table="material_html"
dynamic-update="true" dynamic-insert="true" lazy="true">
<cache usage="read-write" />
<id name="htmlId" type="java.lang.String" column="html_id">
<generator class="util.UniqueIdGene" />
</id>
<property name="title" type="java.lang.String" column="title">
</property>
<property name="htmlCode" type="java.lang.String" column="html_code" lazy="true">
</property>
<many-to-one name="columnNodeBean" class="columnnode.bean.ColumnNodeBean" lazy="proxy" column="column_node_id" cascade="none" ></many-to-one>
</class>

大致关系如上,一个节点下有若干条html素材。
如果只用关键词去检索目前是没有问题,比如我检索方法
public List<HtmlMaterialBean> fullTextSearchForList(String keyWord,String columnNodeId,int pageNum, int pageSize) throws DaoException {
FullTextSession fullTextSession = Search.getFullTextSession(getSession());
String[] keyWords = null;
if(keyWord!=null && keyWord.contains(" ")){
keyWords = keyWord.split(" ");
}else
keyWords = new String[]{keyWord};
BooleanQuery booleanQuery = new BooleanQuery();
MultiFieldQueryParser queryParser = new MultiFieldQueryParser(
new String[]{"title","htmlCode"},new ChineseAnalyzer());
//QueryParser columnParser = new QueryParser("columnNodeId", new ChineseAnalyzer() );
try{
for(String key: keyWords){
if(key!=null && key.trim().length()>0)
booleanQuery.add( queryParser.parse(key), Occur.SHOULD);
}
//booleanQuery.add( columnParser.parse(columnNodeId), Occur.SHOULD);
} catch (ParseException e) {
throw new DaoException(e);
}
Query query = fullTextSession.createFullTextQuery(booleanQuery, HtmlMaterialBean.class,ColumnNodeBean.class);
//query.setMaxResults(2);
List result = query.list();
this.releaseSession(fullTextSession);
return result;
}

目前就是想根据columnNodeBean的nodeId,根据节点ID区分节点来检索。要怎么实现还请各位指点一二。E文文档看的一头雾水~
...全文
102 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
Hibernate Search is a library providing full-text search capabilities to Hibernate. It opens doors to more human friendly and efficient search engines while still following the Hibernate and Java Persistence development paradigm. This library relieves you of the burdens of keeping indexes up to date with the database, converts Lucene results into managed objects of your domain model, and eases the transition from a HQL-based query to a full-text query. Hibernate Search also helps you scale Lucene in a clustered environment. Hibernate Search in Action aims not only at providing practical knowledge of Hibernate Search but also uncovering some of the background behind Hibernate Search’s design. We will start by describing full-text search technology and why this tool is invaluable in your development toolbox. Then you will learn how to start with Hibernate Search, how to prepare and index your domain model, how to query your data. We will explore advanced concepts like typo recovery, phonetic approximation, and search by synonym. You will also learn how to improve performance when using Hibernate Search and use it in a clustered environment. The book will then guide you to more advanced Lucene concepts and show you how to access Lucene natively in case Hibernate Search does not cover some of your needs. We will also explore the notion of document scoring and how Lucene orders documents by relevance as well as a few useful tools like term highlighters.

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧