2014-07-24 132 views
0

我想在我的應用程序中使用hibernate搜索(lucene)實現搜索功能。簡單搜索字符串字段的工作是完美的,但現在事情變得更加複雜.... 我希望你能給我一些提示或樣本。休眠lucene搜索集合和枚舉

我有以下實體...

@Entity 
@Indexed 
public class ChildClass { 

    @Enumerated 
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.YES) 
    private EnumType enumType; 
    .... 

    //getter setter 

} 

=============================== =========

@Entity 
@Indexed 
public class ParentClass { 

@IndexEmbeded 
List<ChildClass> childs; 

    //getter setter... 

} 

================================== ======

public enum EnumType { 
    a,b,c 
} 

===================================== ==

現在,我嘗試搜索和查找,例如:

「找到具有孩子的ParentClasses的一個List,child.enumtype =一個」

我可以用HQL或原生SQL查詢做到這一點。但是如何用hibernate lucene查詢來做到這一點。

在此先感謝

+0

爲澄清: – user2439522

+0

只是爲了澄清 對於地圖例如 \t @Field(index = Index.YES,analyze = Analyze.YES,store = Store。NO) @IndexedEmbedded(depth = 1) private Map comments; \t 我可以使用查詢像: luceneQuery = queryBuilder.keyword()通配符()onField( 「註釋」)匹配( searchString的).createQuery();。 booleanJunction.should(luceneQuery); \t \t \t 這qurey返回結果如預期。 我有上述用例的問題 – user2439522

回答

0

您使用的@IndexedEmbedded並不適用於這種情況下 - 在我看來,你的子類是一個實體,如子實體往常一樣,他們是指他們的父母,所以父類爲他們的孩子有一個雙向映射。

如前所述hereAddress作爲使用情況實例)

爲了確保當它的地址 變化將Lucene的文檔進行更新,則需要雙向 關係的另一側@標記ContainedIn。

@ContainedIn僅對與嵌入(集合)對象相反的實體指向 有用。

也許你可以在child列表上試試@ContainedIn註釋。

總結:

  • 可以使用@IndexedEmbedded從ChildParent(上parent屬性)
  • 可以使用@ContainedIn從ParentCollection<Child>(雙向)
+0

感謝您的回覆,我瞭解到目前爲止,但luceneQurery應該如何用於上面的szenario,因爲您可以看到我已經嘗試了@IndexEmbedded – user2439522