本文介绍了如何使用VB.NET在lucene.net索引中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    Try
        Dim dt_Result As New DataTable
        Dim FinalTable As New DataTable
        Dim strTagSbFld As String
        strTagSbFld = GetTagSbFldSQL()
        Dim searchString As String = txtSearch.Text
        Dim query1 As String = (strTagSbFld)
        'MsgBox(query1)
        conn.Open()
        adap.SelectCommand = New SqlCommand(query1, conn)
        adap.Fill(dt_Result)
        Dim Field0, Field1, Field2, Field3, Field4, Field5 As String


        Field0 = dt_Result.Columns(0).Caption
        Field1 = dt_Result.Columns(1).Caption
        Field2 = dt_Result.Columns(2).Caption
        Field3 = dt_Result.Columns(3).Caption
        Field4 = dt_Result.Columns(4).Caption
        Field5 = dt_Result.Columns(5).Caption

        ' Specify the location where the index files are stored
        Dim indexFileLocation As String = "C:\Users\Shahrukh\Documents\Visual Studio 2012\Projects\Simple search1\Simple search1\New folder"
        Dim dir As Lucene.Net.Store.Directory = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation)

        ' specify the search fields, lucene search in multiple fields
        Dim searchfields As String() = New String() {Field0, Field1, Field2, Field3, Field4, Field5}
        Dim indexSearcher As New IndexSearcher(dir)

        ' Making a boolean query for searching and get the searched hits
        'Dim hits = indexSearcher.Search(QueryMaker(searchString, searchfields))

        If SearchCriteria = "Title" Then
            Dim Searchresults As New List(Of SearchResultsTitle)()
            Dim hits = indexSearcher.Search(QueryMaker(searchString, searchfields))
            For i As Integer = 0 To hits.Length() - 1
                Dim result As New SearchResultsTitle()
                result.SrNo = i + 1
                result.Title = hits.Doc(i).GetField(Field0).StringValue()
                result.Accessionno = hits.Doc(i).GetField(Field2).StringValue()
                result.Location = hits.Doc(i).GetField(Field3).StringValue()
                result.Status = hits.Doc(i).GetField(Field5).StringValue()
                Searchresults.Add(result)
            Next
            indexSearcher.Close()
            'adap.Fill(Searchresults)
            dGridResults.ItemsSource = Searchresults

        conn.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub







我正在使用此代码,但它在sql数据中的搜索不在lucene索引中,所以请帮我在lucene索引中执行搜索。



删除了SHOUTING,修正了代码块, - OriginalGriff [/ edit]




I am using this code for it but its search in sql data not in lucene index so please help me to perform a search in lucene index .

[edit]SHOUTING removed, code block corrected, - OriginalGriff[/edit]

推荐答案


这篇关于如何使用VB.NET在lucene.net索引中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:32