简体   繁体   English

Hibernate Search不会基于对“计算”值的更改来重新编制索引

[英]Hibernate Search is not reindexing based on changes to “calculated” values

We use Hibernate Search (4.1) throughout our application to manage searching and indexing of resources, but sometimes need to manage "calculated" values in the index, eg, calls to @IndexEmbedded or @Field attached to getters without actual properties: 我们在整个应用程序中使用Hibernate Search(4.1)来管理资源的搜索和索引,但是有时需要管理索引中的“计算”值,例如,对@IndexEmbedded或@Field的调用附加到没有实际属性的getter上:

    public class Resource {
            @ManyToMany(...)
            private List<Keyword> keywords = new ArrayList<Keyword>();


            public List<Keyword> getKeywords() {
                    return keywords;
            }

            public List<Keyword> setKeywords(List<Keyword> keyword>) {
                    this.keywords=keywords;
            };


            @IndexedEmbedded
            public List<Keyword> getIndexedKeywords() {
                    List<Keyword> toReturn = new ArrayList<Keyword>();
                    for (Keyword keyword: getKeywords()) {
                            if (keyword.isIndexed) {
                                    toReturn.add(keyword);
                            }
                    }
                    return toReturn;
            }

    }

... ...

public void saveResource(Resource resource, Collection<Keyword> keywords) {
        resource.getKeywords().retainAll(keywords);
        resource.getKeywords().addAll(keywords);
        session.saveOrUpdate(resource);
        // will trigger a persist in the database correctly, but will not trigger a reindex
};

but calling saveResource does not cause HibernateSearch to reindex. 但是调用saveResource不会导致HibernateSearch重新索引。 Shouldn't it? 不是吗

HibernateSearch 4.1 (or anything after 3.4) uses 'smart' checks to see whether reindexing needs to happen, which matches the @IndexedEmbedded calls to Hibernate's persisted fields. HibernateSearch 4.1(或3.4之后的任何版本)使用“智能”检查来查看是否需要进行重新索引编制,这与对Hibernate持久字段的@IndexedEmbedded调用相匹配。 If these do not match, than Hibernate Search does not reindex the object, because the checks do not see anything that matches, and thus will not call reindex. 如果这些不匹配,则Hibernate Search不会为该对象重新索引,因为检查不会看到任何匹配的内容,因此不会调用reindex。 This is likely because HibernateSearch would have to either perform tremendous amounts of reflection and introspection on indexed fields to determine whether underlying values have changed, or calculate and store the result of each call such that it can determine whether the value has changed or not, thus both slowing down the reindexing process and/or bloating the lucene index with a stored hash or entire result value. 这很可能是因为HibernateSearch必须对索引字段执行大量的反射和自省以确定基础值是否已更改,或者计算并存储每个调用的结果,以便可以确定值是否已更改,因此既会减慢重新索引过程的速度,又会/或使用存储的哈希值或整个结果值使lucene索引膨胀。 Probably best to simply either taint a field that causes the reindexing, or manually reindex the object at the end. 最好是简单地污染导致重新索引的字段,或者最后手动对对象重新索引。

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

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