2012-08-14 46 views
2

我們希望索引並將一組Word文檔存儲在Solr中,並將它們顯示爲多值文本字段的元素,每個文檔的內容都顯示爲元素在索引中的那一個條目下。換句話說,它看起來像這樣Solr - 爲單個唯一ID存儲多個Word文檔

  • ID
    • ABCDEF [Word_1.docx的文本]
    • XYZABC [Word_2.docx的文本]
    • efghij [Word_3.docx的文本]

我們不希望每個索引的文檔都有自己唯一的ID;一組文件將是特定身份證件的子女。該ID可以有任意數量的文件。 如何做到這一點?

更新:這是我的C#代碼;我將如何讀取多個文件到這個爲(++count).ToString()設置的唯一ID?

using (FileStream fileStream = File.OpenRead(path)) 
{ 

    solr.Extract(
     new ExtractParameters(fileStream, (++_count).ToString()) 
      { 
       ExtractFormat = ExtractFormat.Text, 
       ExtractOnly = false, 
       Fields = new List<ExtractField>() 
               { 
                new ExtractField("action", actionTo), 
                new ExtractField("actiondate", actionDate), 
                new ExtractField("abstract", abstract), 
                new ExtractField("docval", docval), 
                new ExtractField("documentgeo",documentgeo), 
                new ExtractField("filename", filename), 
                new ExtractField("isprimary", IsPrimary.ToString()) 
               }, 
            AutoCommit = true 
      } 
     ); 
} 
+0

https://groups.google.com/d/topic/solrnet/DuHv0EGK_y4/discussion – 2012-08-14 22:58:03

回答

3

在你的Solr模式定義兩個領域 - idtexttext應該是多值的。然後在您的SolrInputDocument中彙總id和索引的文本數據。

<field name="id" type="int" multiValued="false" stored="true" indexed="true" /> 
<field name="text" type="text" multiValued="true" stored="true" indexed="true" /> 

我不知道c# API,但使用SolrJ是相當容易使用SolrInputDocument.addField("fieldname", "value")聚集。

示例更新

SolrInputDocument doc = new SolrInputDocument(); 
doc.addField("id", 1) 
for (String docText : documents){ 
    doc.addField("text", docText) 
} 

實例.NET更新

我會定義下列方式我的課:

public class Document{ 
[SolrUniqueKey("id")] 
public integer Id { get; set; } 

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

然後,我將填充它,並提交像這樣的僞.NET代碼:

Document doc = new Document(); 
for (String documentPath : paths) { 
    using (FileStream fileStream = File.OpenRead(path)) { 
     string id = fileStream.getId(); 
     if (doc.getId() == id){ 
      doc.getTexts.add(fileStream.getText()) 
     } 
    } 
} 
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Document>>(); 
solr.Add(doc); 
solr.Commit(); 
+0

也許我不理解代碼,但這並沒有考慮到要編制索引的多個文檔。你如何使用'SolrInputDocument.addField()'方法?你是否在代碼中向模式添加了一個新字段?另外,我無法在SolrNet中找到相應的語法。 – Alex 2012-08-14 11:42:02

+0

SolrNet示例位於http://code.google.com/p/solrnet/wiki/CRUD我還建議您查看SolrNet Source中的SampleApp - https://github.com/mausch/SolrNet/tree/master/SampleSolrApp – 2012-08-14 11:44:03

+0

謝謝,Paige。從文檔來看,SolrNet似乎不支持這一點。或者文檔沒有提到它。 – Alex 2012-08-14 11:51:03