• Lucene.Net小实例 VB.NET


    Imports Lucene.Net.Analysis.Standard
    Imports Lucene.Net.Analysis
    Imports Lucene.Net.Index
    Imports Lucene.Net.Documents
    Imports System.IO
    Imports Lucene.Net.Search
    Imports Lucene.Net.QueryParsers


    Partial Class _Default
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            'Dim str As String = "我们是中国人; 我们 是 人;we are chiness; 172.16.34.172;youpeizun@126.com;#$*;85*34;58 69"
            'Response.Write(Me.TestStandardTokenizer(str))
        End Sub

        Private Function TestStandardTokenizer(ByVal text As String) As String
            Dim result As String = ""
            Dim tr As TextReader = New StringReader(text)
            Dim st As StandardTokenizer = New StandardTokenizer(tr)
            While (Not st.Next() Is Nothing)
                result = result & st.token.ToString() & "/ "
            End While
            Return result
        End Function
       
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim INDEX_STORE_PATH As String = Server.MapPath("Index")
            Dim INDEX_PATH As String = TextBox1.Text

            Dim writer As IndexWriter
            writer = New IndexWriter(INDEX_STORE_PATH, New StandardAnalyzer(), True)

            IndexDirectory(writer, New FileInfo(INDEX_PATH))
            writer.Optimize()
            writer.Close()

            TextBox2.Text = "提示:索引完成\n"


        End Sub

        Private Sub IndexDirectory(ByVal writer As IndexWriter, ByVal file As FileInfo)
            If Directory.Exists(file.FullName) Then
                Dim files As String() = Directory.GetFileSystemEntries(file.FullName)
                If Not files Is Nothing Then
                    Dim i As Integer
                    For i = 0 To files.Length - 1
                        IndexDirectory(writer, New FileInfo(files(i)))
                    Next
                End If
            ElseIf file.Extension = ".txt" Then
                IndexFile(file, writer)
            End If
        End Sub

        Private Sub IndexFile(ByVal file As FileInfo, ByVal writer As IndexWriter)
            Dim doc As Document = New Document()
            doc.Add(New Field("filename", file.FullName, Field.Store.YES, Field.Index.UN_TOKENIZED))
            doc.Add(New Field("contents", New StreamReader(file.FullName, System.Text.Encoding.Default)))
            writer.AddDocument(doc)
        End Sub

        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim INDEX_STORE_PATH As String = Server.MapPath("index")   'INDEX_STORE_PATH 为索引存储目录
            Dim KEYWORD As String = TextBox2.Text '搜索关键字

            Dim searcher As IndexSearcher
            searcher = New IndexSearcher(INDEX_STORE_PATH)

            Dim q As QueryParser = New QueryParser("contents", New StandardAnalyzer())
            Dim query As Query = q.Parse(KEYWORD)

            Dim hits As Hits = searcher.Search(query)
            TextBox3.Text = "Results number is " & hits.Length()

            If Not hits Is Nothing Then
                Dim i As Integer
                For i = 0 To hits.Length - 1
                    Dim doc As Document = hits.Doc(i)
                    TextBox3.Text = TextBox3.Text & " 第" & i & "个结果地址" & doc.Get("filename") & "\n"
                Next
            End If
            searcher.Close()

        End Sub
    End Class

  • 相关阅读:
    图像融合之拉普拉斯融合(laplacian blending)
    真实场景的虚拟视点合成(View Synthsis)详解
    真实场景的双目立体匹配(Stereo Matching)获取深度图详解
    OpenCV亚像素角点cornerSubPixel()源代码分析
    OpenCV角点检测goodFeaturesToTrack()源代码分析
    OpenCV角点检测源代码分析(Harris和ShiTomasi角点)
    引导图滤波(Guided Image Filtering)原理以及OpenCV实现
    OpenCV3.4两种立体匹配算法效果对比
    文件操作常用函数
    two Pass方法连通域检测
  • 原文地址:https://www.cnblogs.com/twilight/p/1522207.html
Copyright © 2020-2023  润新知