2009-04-07 59 views
0

如何查詢添加爲IndexEmbedded的數據?
我有一個實體類如何查詢索引爲IndexEmbedded的數據(全文在nhibernate.search中)

[Indexed] 
    public class Something 
    { 
    [Field(Index.Tokenized, Store = Store.Yes)] 
    public virtual string Description { get; set; } 

    [IndexedEmbedded] 
    public virtual Category Category { get; set; } 
    [IndexedEmbedded] 
    public virtual Location Location { get; set; } 
    } 

位置作爲

[Indexed] 
    public class Location 
    { 
    /// </summary>    
    [Field(Index.Tokenized, Store = Store.Yes)] 
    public virtual string Address 
    { 
    } 

被添加數據(無論是正常的性能和IndexEmbedded)的指數,我可以將它們用盧克看到。
但是,當我使用全文查詢時,我只獲得有效結果的正常屬性,而不是索引嵌入
例如, 「取樣說明」 => 1分的結果,「帕洛阿爾託」 => 0的結果(兩者都是在指數) 這是我的查詢

using (IFullTextSession s = Search.CreateFullTextSession(NHibernateSession.GetSession())) { 
     MultiFieldQuerParser qp = new MultiFieldQueryParser(new[] { 
                    「Description」,「Title」,」Name」 
                    }, new StandardAnalyzer()); 
     IQuery NHQuery = s.CreateFullTextQuery(qp.Parse(query), typeof(Something)); 
     result = NHQuery.List(); 

我做得不對或缺少什麼?

回答

2

從我看到的,你沒有引用IndexedEmbedded集合的字段。您應該添加以下字段在MultiFieldQueryParser

new MultiFieldQueryParser(new[] {"Description", "Title", "Name", "Location.Address"}) 

爲字段中輸入正確的名字應該在盧克是可見的,與物業名稱爲前綴您應用IndexedEmbedded屬性。


編輯:如果默認前綴是不是你喜歡的,你可以用的前綴參數更改IndexedEmbedded屬性

相關問題