简体   繁体   English

休眠搜索中的双向搜索

[英]Bidirectioal search in Hibernate Search

I have come upon a problem in our application using Hibernate Search. 我在使用Hibernate Search的应用程序中遇到了一个问题。

We have a class, A where we do hsearch against fields in class A and B and also Spatial search agaist class Address declared in A. Everything works nicely. 我们有一个类A,我们在其中搜索类A和B中的字段,还对A中声明的空间搜索反对类Address进行了搜索。一切工作正常。

Now we have to implement search the other way around also, we want to search class B for fields contained in B, A and spatial search against A.Address. 现在,我们还必须以另一种方式实现搜索,我们要在类B中搜索B,A中包含的字段,并针对A.Address进行空间搜索。 Now we have a problem. 现在我们有一个问题。 Since B has A declared as @ContainedIn , the fields of A isn't searcheable from B. If we change @ContainedIn to @IndexEmbedded we get circular dependency because you can't have @IndexEmbedded on both sides. 由于B有一个声明为@ContainedIn ,A领域不是从B.如果我们改变searcheable @ContainedIn@IndexEmbedded我们得到循环依赖,因为你不能有@IndexEmbedded两侧。 Then I read that you can limit the depth on @IndexEmbedded so I tried that. 然后我读到您可以限制@IndexEmbedded的深度,所以我尝试了这一点。 I know that we aren't going to search deeper than A.?.?.? 我知道我们不会比A。?。?。?更深入地搜索 in B so I changed @ContainedIn to @IndexEmbedded(depth = 4) on class A in class B. 在乙所以我改变@ContainedIn@IndexEmbedded(depth = 4)上的A类中的类B.

Now when I start my application I get the following error: 现在,当我启动我的应用程序时,出现以下错误:

org.hibernate.search.SearchException: HSEARCH000158: Class Address cannot have two @Spatial using default/same name org.hibernate.search.SearchException:HSEARCH000158:类地址不能使用默认名称/相同名称的两个@Spatial

Has anyone any tips on how to solve this? 有没有人提示如何解决这个问题? We use Hibernate Search version 4.5.0.Final Se the classes below. 我们使用Hibernate Search版本4.5.0.Final Se下面的类。 Regards Andreas 问候安德烈亚斯

@Entity
@Indexed
@FullTextFilterDefs({
        @FullTextFilterDef(name = "externalSearchFilterFactory", impl = ExternalSearchFilterFactory.class),
        @FullTextFilterDef(name = "internalSearchFilterFactory", impl = InternalSearchFilterFactory.class)
})
@DynamicUpdate(value = true)
@Table(name = "A")
public class A extends DomainObjekt {

    .....

    @IndexedEmbedded
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE, optional = false)
    @JoinColumn(name = "B_ID", referencedColumnName = "B_ID", nullable = false)
    private B b;

    @IndexedEmbedded
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE, optional = false)
    @JoinColumn(name = "ADDRESS_ID", referencedColumnName = "ADDRESS_ID", nullable = false)
    private Address adress;

    .....

} 


@Entity
@Indexed
@DynamicUpdate(value = true)
@Table(name = "B")
public class B extends DomainObjekt {

    .....

    @ContainedIn
    @OneToMany(mappedBy = "b", fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
    private Set<A> listOfA = new HashSet<A>();

    .....
}

@Spatial(name = "location", spatialMode = SpatialMode.RANGE)
@Indexed
@Entity
@DynamicUpdate(value = true)
@Table(name = "ADDRESS")
@SuppressWarnings({"serial"})
public class Address extends DomainObjekt {

    .....

    @Latitude(of = "location")
    @Column(name = "LATITUDE")
    private Double latitude;

    @Longitude(of = "location")
    @Column(name = "LONGITUDE")
    private Double longitude;

    .....
}

The @Spatial annotation takes a name attribute. @Spatial批注采用name属性。 You should use this attribute when you want to have multiple spatial fields in the same entity, so that you can point to a specific one when doing queries. 如果要在同一实体中具有多个空间字段,则应使用此属性,以便在执行查询时可以指向特定的一个。

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

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