【问题标题】:Retrieve Hibernate Search results directly from Lucene Index直接从 Lucene Index 检索 Hibernate Search 结果
【发布时间】:2012-09-10 18:35:03
【问题描述】:

如何使用 Hibernate Search 执行搜索,该搜索不会从数据库中检索实际实体,而只会返回这些实体的文档缓存记录?我确保将我需要的字段存储在索引中。在此过程中数据库将处于活动状态且可用,我只是想减少不必要的负载。

@Column
@Field (index = Index.YES, store = Store.YES)
private String title;

@Id
@Column
@DocumentId
@Field (store = Store.YES)
private String guid;

Session sess = sessionFactory.openSession();
FullTextSession fts = org.hibernate.search.Search.getFullTextSession(sess);
//returns matching Articles from database, how would I retrieve only the index records?
Query query = fts.createFullTextQuery(luceneQuery, Article.class);  

版本:

休眠搜索 4.1.1.Final

Hibernate Core 4.1.6.Final

Lucene 3.5

【问题讨论】:

    标签: hibernate lucene full-text-search hibernate-search


    【解决方案1】:

    查看 docs 中描述的 Hibernate Search 的投影功能。 关键是使用要从索引中检索的字段名称列表调用 query.setProjection。比如:

    query.setProjection( "field1", "field2", "field3" );
    

    请注意,结果是您将获得对象数组而不是托管的 Hibernate 实体。

    【讨论】:

      猜你喜欢
      • 2016-02-28
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多