mssun / passforios

Pass for iOS - an iOS client compatible with Pass command line application.
https://mssun.github.io/passforios
MIT License
1.5k stars 102 forks source link

Search algorithm improvement? #614

Open hckiang opened 1 year ago

hckiang commented 1 year ago

I have been using the app for years but now as my password store grows bigger, the search algorithm now can seldom find the entry that I want. For example, when I type Pinboard in the search box these are the first few file names that matches:

Amazon.co.uk Sign in
anonymous in "Linux box" Virtualbox
bourbaki wifi raspberry pi
Facebook Mobile PIN
Hidden app in Microsoft Launcher
hkjc pin

In the above, it seems that in is matching Pinboard. The 'most sensible' entry pinboard.in is at the 18th position.

Another example: the query Facebook will actually match the file name BCM e-banking, which IMHO is too fuzzy. I suspect this is some Levenshtein distance algorithm(?)

QtPass, on the other hand, appears to just tokenises the search query then find file names that matches any one of the tokens. It isn't perfect but most of the time it can find the thing that I need in one go.

Any chance this can be improved?

hckiang commented 1 year ago

I think this function here could look like this:

    public static func match(nameWithCategory: String, searchText: String) -> Bool {
        let querywords = searchText.split {!($0.isLetter || $0.isNumber || $0 == ".") }
        for str in querywords {
            if nameWithCategory.localizedCaseInsensitiveContains(str) {
                return true
            }
        }
        return false
    }