如何仅以一种可读的xml格式创建lucene索引

时间:2015-11-19 05:07:27

标签: vb.net lucene.net

我正在使用下面的代码,但它提供了很多文件,我只想要一个xml格式的文件,所以请给我一个正确的方法来创建xml格式的lucene索引。

Dim BibliDS As New DataSet
Dim DataDS As New DataSet
Dim dt As DataTable

Dim strTagSbFld As String
strTagSbFld = GetTagSbFldSQL()

conn.Open()
Dim strSQL As String = (strTagSbFld)
adap.SelectCommand = New SqlCommand(strSQL, conn)
adap.Fill(DataDS)
conn.Close()
DataDS.WriteXml("C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder\Data.xml")
'MsgBox("XML Done")
Dim directory As Directory = FSDirectory.GetDirectory("C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder ")

Dim analyzer As Lucene.Net.Analysis.Analyzer = New SimpleAnalyzer()
Dim indexWriter As New IndexWriter(directory, analyzer)
indexWriter.SetRAMBufferSizeMB(10.0)
indexWriter.SetUseCompoundFile(False)
indexWriter.SetMaxMergeDocs(10000)
indexWriter.SetMergeFactor(100)

dt = DataDS.Tables(0)
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
For Each dr As DataRow In dt.Rows
'Create the Document object
Dim doc As New Document()
For Each dc As DataColumn In dt.Columns
'Populate the document with the column name and value from our query
doc.Add(New Field(dc.ColumnName, dr(dc.ColumnName).ToString(), Field.Store.YES, Field.Index.TOKENIZED))
Next
' Write the Document to the catalog
indexWriter.AddDocument(doc)
Next
End If
Else
MsgBox("No Data")
End If
'indexWriter.Optimize()
'Close the writer
indexWriter.Flush()
indexWriter.Close()

End Sub

请给我一个正确的方法,只在一个xml格式的文件中创建一个lucene索引。

1 个答案:

答案 0 :(得分:1)

简短回答:你不能。

无论如何,你为什么要这样做?表现会非常糟糕。

要概述lucene创建的不同文件,请查看Index File Formats