Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    fuzzy text search (XP/2K)

    Is there a better way to do what I am trying to do?
    This function is to create a string for all possibilities to use as a filter on a form, using "*"

    Public Function fFuzzySearch(strWord) As String

    Dim strResult As String
    Dim intLength1 As Integer ' this gets subtracted from during the loop
    Dim intLength2 As Integer ' this keeps the original length
    Dim strTemp1 As String 'this is the result of the loop now running
    Dim strTemp2 As String ' this keeps the result from the previous loop

    On Error GoTo fFuzzySearch_Error
    strTemp2 = ""
    intLength1 = Len(strWord)
    intLength2 = Len(strWord)
    Do Until intLength1 = 0
    strTemp1 = Left(strWord, 1)
    strTemp1 = strTemp1 & "*"
    strTemp2 = strTemp2 & strTemp1
    strWord = Right(strWord, intLength1 - 1)
    intLength1 = intLength1 - 1

    Loop
    strResult = Left(strTemp2, (intLength2 * 2) - 1)

    fFuzzySearch = strResult

    On Error GoTo 0
    Exit Function

    fFuzzySearch_Error:
    Call LogError(Err.Number, Err.Description, "fFuzzySearch")
    End Function


    Any suggestions would be welcome.
    Thanks

  2. #2
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: fuzzy text search (XP/2K)

    I suspect you may have been asking a bigger question, but for what it's worth:

    Public Function fFuzzySearch(strWord) As String
    On Error GoTo fFuzzySearch_Error

    Dim strTemp As String
    Dim x As Long

    'A string variable initializes as an empty string, so
    ' the next line is unnecessary.
    ' strTemp = ""

    For x = 1 To Len(strWord)
    strTemp = strTemp & Mid(strWord, x, 1) & "*"
    Next x

    fFuzzySearch = Left(strTemp, Len(strTemp) - 1)

    'The next line is unnecessary. Exiting the function resets On Error.
    ' On Error GoTo 0
    Exit Function

    fFuzzySearch_Error:
    Call LogError(Err.Number, Err.Description, "fFuzzySearch")

    End Function

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: fuzzy text search (XP/2K)

    thanks.
    I was also asking the bigger question- is this brute force method the way to go about it.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: fuzzy text search (XP/2K)

    Your function (or St333ve's streamlined version of it) require that all letters of a word are present; variants such as "disk" and "disc" will not be seen as the same.

    Consider using a soundex function for comparing strings. See <post#=137782>post 137782</post#> for a standard version, and <post#=129020>post 129020</post#> for a modified version that may be better for fuzzy searches.

  5. #5
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: fuzzy text search (XP/2K)

    Thanks hans. I am working in hebrew, I will search if there is a soundex table for hebrew.

  6. #6
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: fuzzy text search (XP/2K)

    How would I Implement this on a regular basis on searching records? Would you store each existing record's soundex code, and then search that field? I cannot see searching 65,000 records and computing the code for each one as you search?
    Thanks

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: fuzzy text search (XP/2K)

    Yes, if you have a large table, you would create a soundex field in the table, otherwise searching would be excruciatingly slow.
    Create and run an update query to populate the field for existing records (this is a one-time operation.)
    Use code in the Before Update event of the form used to edit the records to fill/update the field for new and modified records.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •