用 Hibernate 标记云 Search/Lucene?
Tag Cloud with Hibernate Search/Lucene?
我们的网络应用程序有一个产品类别数据库,其中有 n 种产品。每个产品可以有 0 个或多个与之关联的标签。所有这些对象都使用 Hibernate Search (JPA) 进行索引。我们正在尝试使用这些标签构建标签云,以便更轻松地查看最受欢迎的内容。我们的代码看起来像这样...
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(this.entityManager);
SearchFactory searchFactory = fullTextEntityManager.getSearchFactory();
IndexReader indexReader = searchFactory.getIndexReaderAccessor().open(ProductBean.class);
TermStats[] termStats = null;
int numResults = 500;
String field = "tags.name";
try {
termStats = org.apache.lucene.misc.HighFreqTerms.getHighFreqTerms(indexReader, numResults, field,
new org.apache.lucene.misc.HighFreqTerms.DocFreqComparator());
} finally {
searchFactory.getIndexReaderAccessor().close(indexReader);
}
此代码按我们预期的方式工作,并为我们提供了一组 TermStats 对象,这些对象为我们提供了构建标签云所需的评分信息。但是,现在我们想在每个类别的基础上构建标签云。也就是说,我们希望能够根据特定产品所属的类别来过滤我们的结果。但是,我们还没有找到一种方法来做到这一点,因为 IndexReader 似乎没有允许我们附加任何类型的过滤器。
有没有人完成过类似的事情?有没有更好的方法来使用 Hibernate Search 构建标签云?
我想你可以尝试使用 lucene 方面 (https://lucene.apache.org/core/4_0_0/facet/org/apache/lucene/facet/doc-files/userguide.html)
它们允许您添加某种 "group by" 并依靠搜索结果。
我们的网络应用程序有一个产品类别数据库,其中有 n 种产品。每个产品可以有 0 个或多个与之关联的标签。所有这些对象都使用 Hibernate Search (JPA) 进行索引。我们正在尝试使用这些标签构建标签云,以便更轻松地查看最受欢迎的内容。我们的代码看起来像这样...
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(this.entityManager);
SearchFactory searchFactory = fullTextEntityManager.getSearchFactory();
IndexReader indexReader = searchFactory.getIndexReaderAccessor().open(ProductBean.class);
TermStats[] termStats = null;
int numResults = 500;
String field = "tags.name";
try {
termStats = org.apache.lucene.misc.HighFreqTerms.getHighFreqTerms(indexReader, numResults, field,
new org.apache.lucene.misc.HighFreqTerms.DocFreqComparator());
} finally {
searchFactory.getIndexReaderAccessor().close(indexReader);
}
此代码按我们预期的方式工作,并为我们提供了一组 TermStats 对象,这些对象为我们提供了构建标签云所需的评分信息。但是,现在我们想在每个类别的基础上构建标签云。也就是说,我们希望能够根据特定产品所属的类别来过滤我们的结果。但是,我们还没有找到一种方法来做到这一点,因为 IndexReader 似乎没有允许我们附加任何类型的过滤器。
有没有人完成过类似的事情?有没有更好的方法来使用 Hibernate Search 构建标签云?
我想你可以尝试使用 lucene 方面 (https://lucene.apache.org/core/4_0_0/facet/org/apache/lucene/facet/doc-files/userguide.html)
它们允许您添加某种 "group by" 并依靠搜索结果。