0
我正在使用Lucene.Net 3.0.3,我有工作代码,但我无法弄清楚如何添加一个简单的格式化程序。为Lucene.net创建一个简单的高亮格式化工具3.0.3
Public Function Lucene_Index_Search_Complete(term As String) As String
Dim sb As New StringBuilder()
Dim sw As New StringWriter(sb)
Dim writer As JsonWriter = New JsonTextWriter(sw)
Try
Dim d As Lucene.Net.Store.Directory = FSDirectory.Open(New DirectoryInfo(Server.MapPath("~") + "\\IndexedFiles_V33\\"))
Dim indexReader As IndexReader = indexReader.Open(d, True)
Dim indexSearch As Searcher = New IndexSearcher(indexReader)
Dim a As Analyzer = New StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)
'IFormatter formatter = new SimpleHTMLFormatter("<b>", "</b>");
Dim HighlightFormatter As SimpleHTMLFormatter = New SimpleHTMLFormatter("<span style='background:yellow;'>", "</span>")
Dim FieldNames As String() = indexReader.GetFieldNames(indexReader.FieldOption.INDEXED_NO_TERMVECTOR).toArray
Dim parser As MultiFieldQueryParser = New MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, FieldNames, a)
Dim q As BooleanQuery = New BooleanQuery()
term = term.Trim
Dim phases As String() = Nothing
If term.contains(",") Then
phases = Split(term, ",")
For Each phase As String In phases
q.Add(parser.Parse(phase), Occur.SHOULD)
Next
Else
phases = Split(term, " ")
For Each phase As String In phases
q.Add(parser.Parse(phase), Occur.MUST)
Next
End If
Dim collector As TopScoreDocCollector = TopScoreDocCollector.create(1000, True)
indexSearch.Search(q, collector)
Dim hits As ScoreDoc() = collector.topDocs().scoreDocs
Dim GrantID As String = ""
Dim Title As String = ""
Dim Posted_Date As String = ""
Dim link As String = ""
Dim jsonData As JObject = Nothing
Dim purpose As String = ""
Dim Short_Description As String = ""
' Loop through the matching hits, retrieving the document
writer.WriteStartArray()
For i As Integer = 0 To hits.Length - 1
Try
If i >= 50 Then
Exit For
End If
Dim docId As Integer = hits(i).doc
Dim doc As Document = indexSearch.doc(docId)
Dim Score As String = hits(i).Score.tostring
GrantID = doc.get("GrantID")
link = doc.get("link")
jsonData = JObject.Parse(doc.get("JSON_Data"))
Title = jsonData("Funding Opportunity Title").ToString
Posted_Date = jsonData("Posted Date").ToString
purpose = jsonData("Funding Opportunity Purpose").ToString
writer.WriteStartObject()
writer.WritePropertyName("id")
writer.WriteValue((1 + i).ToString)
writer.WritePropertyName("Grant_ID")
writer.WriteValue(GrantID)
writer.WritePropertyName("text")
writer.WriteValue("<br/>" + Title + "<br/>" + purpose + "<br/><b>Score:</b> " + Score + "<br/>")
writer.WritePropertyName("Score")
writer.WriteValue(Score)
writer.WriteEndObject()
Catch ex As Exception
WriteErrorLog(ex.Message, link)
End Try
Next
writer.Close()
Return sb.ToString
Catch ex As Exception
Return ex.Message
End Try
End Function
我想要做的就是用黄色背景包装这个词。任何帮助表示赞赏,因为我已经寻找答案,我认为我必须失去一些东西。我需要强调的是在融资机会的目的和资金机会标题
好像你的问题的标题应该改变。 'Lucene.net 3.0.3'对于尝试查找有关向lucene添加格式化程序的信息没有帮助。我不确定是否可以通过 – mdiehl13
追溯更改标题/问题我同意 - 我更改了它 - 谢谢 – user1314159
您应该添加解决方案作为答案,以便人们知道这已得到解决。 – NightOwl888