2013-12-18 32 views
0

我使用Solr 4.6與Jetty和作爲客戶端最新的solrnet版本(1672)。我沒有對solrconfig.xml或schema.xml做任何更改,因爲我需要的只是文檔的內容和標識。我的班級:Solr重點錯誤

public class Register 
{ 
    [SolrUniqueKey("id")] 
    public string Id { get; set; } 

    [SolrField("content")] 
    public string Content { get; set; } 

    [SolrField("text")] 
    public string Text{get;set;} 
} 

我將文檔插入Solr的用代碼:

using (FileStream fileStream = File.OpenRead(filePath)) 
      { 
       var response = 
        Solr.Extract(
         new ExtractParameters(fileStream, txtId.Text) 
         {        
          ExtractFormat = ExtractFormat.Text, 
          ExtractOnly = false, 

         });    

          } 

      Solr.Commit(); 

我的問題是,我不能讓亮點工作。我對highlightning代碼:

QueryOptions options = 
new QueryOptions{Highlight = new HighlightingParameters{Fields = new[] {"id", "content", "text"}}}; 
       SolrQueryByField query = new SolrQueryByField("text", "nhibernate"); 
       var res = Solr.Query(query, options); 

在執行第三行我收到一個錯誤:

{「無法轉換值‘System.Collections.ArrayList’文檔類型SolrTest的特性‘內容’ .Register「}

這裏有什麼問題?我遵循this link

回答

2

你的問題是,在默認的schema.xml文件中,content字段是用multiValued=true定義的。告訴Solr在單個文檔中允許該字段有多個值,例如以數組形式存儲。因此,你需要在你的註冊類來更改內容屬性如下:

[SolrField("content")] 
public ICollection<string> Content { get; set; } 

正如SolrNet Mapping documentation所示。

+0

由於內容字段沒有複製到任何地方,我不知道它爲什麼映射到multiValue屬性?我已經在schema.xml中更改了這個,只是刪除了multiValued並且很酷。但是,我也同意你的回答。有一件事現在還不清楚:我的查詢中有6個亮點。每個突出顯示的關鍵值都存在,但值爲空。其實價值應該是文本的片段? – FrenkyB

+1

可能是您的指定字段中沒有任何匹配的突出顯示。由於您正在查詢文本字段(這是來自各種其他字段的copyField目標),因此其他字段可能會驅動查詢並且不會在高亮顯示中顯示。您可以指定「*」作爲高亮區域,以查看是否獲得任何結果。同時檢查突出顯示參數http://wiki.apache.org/solr/HighlightingParameters,因爲有很多選項需要考慮。另外我會建議最初直接對Solr進行測試,以確保您獲得預期的結果。 –