Does Microsoft Access have Full Text Search?

后端 未结 6 1854
闹比i
闹比i 2021-01-11 14:47

Does Microsoft Access have Full Text Search?

I know that MySQL and SQL Server have Full Text Search, but I am not too certain on Access.

If Access doesn\'t h

6条回答
  •  青春惊慌失措
    2021-01-11 15:30

    The first step in full text searching is to create a word list containing all the words in the database. Full text searching also has other features like stemming, which relates derived words to a base word (fast, faster, fastest) and it has stop words which are ignored because they are so common (and, the). A little VBA code can generate a word list which can be visually scanned. With a little more work, it would be possible to use code to check the word list first before searching the database and this might make searches much faster. Below is some code that I created for the purpose. Its real life application is to find peoples names in database so that I can remove or alter them for privacy protection and as a biologist, I want to italicize scientific names in reports. If I can create a list of scientific names, then I can replace them with the name enclosed in html tags.

    The code works well but I have not tested it extensively or against large memo fields/rich text fields. It was written in Access 2010.

    'This code requires a table called tblWordList with fields called Word (str 255), WordCount (long), FirstCopyID (long)
    
    Option Compare Database
    Option Explicit
    
    'Click on this procedure and press F5 to run the code
    Private Sub ScopeWordList()
    
        'A list of tables and fields that need to be processed
        Call CreateWordList("Issues", "IssueSummary", "IssueID")
    
    End Sub
    
    'The main routine that finds new words
    Public Sub CreateWordList(TableName As String, FieldName As String, ForeignKey As String)
    
        Dim dbs As Database
        Dim rst As Recordset
        Dim SQL_Statement As String
    
        Dim r As Recordset
    
        Dim RowText As String
        Dim OriginalWord As String
        Dim SearchWord As String
        Dim SearchTerm As String
        Dim Quote As String: Quote = Chr$(34)
        Dim i As Long
        Dim RecNum As Long
    
        SQL_Statement = "SELECT " & FieldName & ", " & ForeignKey & " AS FirstCopyID FROM " & TableName & " WHERE " & FieldName & " IS NOT NULL;"
        Set dbs = CurrentDb()
        Set rst = dbs.OpenRecordset(SQL_Statement, dbOpenSnapshot)
    
        Set r = dbs.OpenRecordset("tblWordCounts", dbOpenTable)
        r.Index = "Word"
    
        With rst
        If .RecordCount = 0 Then GoTo ExitCreateWordList
    
        Do Until .EOF
            Dim RowWords As Variant 'holds an array which needs to be created
            RowText = .Fields(0)
            'strip out quotes, slashes and other characters
            RowText = CleanLine(RowText)
            'split data into words
            RowWords = Split(RowText, Space(1))
    
            For i = LBound(RowWords) To UBound(RowWords)
                OriginalWord = RowWords(i)
                SearchWord = Left(Trim(OriginalWord), 254)
                If Len(SearchWord) > 0 Then
                        r.Seek "=", SearchWord
                        If r.NoMatch Then
                            r.AddNew
                            r!Word = SearchWord
                            r!wordcount = 1
                            'records ID field of first occurrence, so you can debug unexpected results
                            r!FirstCopyID = !FirstCopyID
                            r.Update
                        Else
                            r.Edit
                            r!wordcount = r!wordcount + 1
                            r.Update
                        End If
                    End If
    '            End If
            Next i
            RecNum = RecNum + 1
            If RecNum Mod 20 = 0 Then Debug.Print "Record " & RecNum
            .MoveNext
        Loop
    
    ExitCreateWordList:
        End With
        Debug.Print "Done"
        Set rst = Nothing
        Set dbs = Nothing
    
    
    End Sub
    
    'Need to clean out unwanted characters and replace then with normal spaces
    Private Function CleanLine(RowText As String) As String
    
            Dim X As Long
            Dim Y As String
            Dim Z As Long
            Dim W As String
    
            For X = 1 To Len(RowText)
                Y = Mid(RowText, X, 1)
                Z = Asc(Y)
                Select Case Z
                    Case 65 To 90      'capital letters
                        W = W & Y
                    Case 97 To 122     'lowercase letters
                        W = W & Y
                    Case Else
                        W = W & Space(1)
                End Select
            Next
            CleanLine = W
    
    End Function
    
    'Delete all records in Word List table
    Public Sub ClearWordList()
    
        Dim SQL_Statement As String
    
        'Delete all records from tblWordCounts
        SQL_Statement = "DELETE FROM tblWordCounts"
        DoCmd.SetWarnings False
        DoCmd.RunSQL SQL_Statement
        DoCmd.SetWarnings True
    
    End Sub
    

提交回复
热议问题