简体   繁体   English

使用 Hibernate Search/Lucene 标记云?

[英]Tag Cloud with Hibernate Search/Lucene?

Our web application has a database of product categories, within which are n number of products.我们的 Web 应用程序有一个产品类别数据库,其中有 n 个产品。 Each product can have 0 or more tags associated with it.每个产品可以有 0 个或多个与之关联的标签。 All of these objects are indexed using Hibernate Search (JPA).所有这些对象都使用 Hibernate Search (JPA) 编制索引。 We're trying to build a tag cloud using these tags, to make it easier to see what are the most popular.我们正在尝试使用这些标签构建标签云,以便更轻松地查看最流行的内容。 Our code looks something like this...我们的代码看起来像这样......

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);
        }

This code works as we would expect, and provides us an array of TermStats objects that give us the scoring info necessary to build the tag cloud.此代码按我们的预期工作,并为我们提供了一组 TermStats 对象,这些对象为我们提供构建标签云所需的评分信息。 However, now we would like to build tag clouds on a per-category basis.但是,现在我们想在每个类别的基础上构建标签云。 That is, we'd like to be able to filter our the results based on the category that a particular product is in. We haven't been able to figure out a way to do this, however, since IndexReader doesn't seem to allow us to attach any sort of filter.也就是说,我们希望能够根据特定产品所在的类别过滤我们的结果。但是,我们还没有找到一种方法来做到这一点,因为 IndexReader 似乎没有允许我们附加任何类型的过滤器。

Has anyone accomplished anything similar to this?有没有人完成过类似的事情? Is there a better way to build a tag cloud using Hibernate Search?有没有更好的方法来使用 Hibernate Search 构建标签云?

I think you can try using the lucene facets ( https://lucene.apache.org/core/4_0_0/facet/org/apache/lucene/facet/doc-files/userguide.html )我认为您可以尝试使用 lucene 方面( https://lucene.apache.org/core/4_0_0/facet/org/apache/lucene/facet/doc-files/userguide.html

They allow you to add some sort of "group by" and count on the search result.它们允许您添加某种“分组依据”并依靠搜索结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM