krisk / fuse-swift

A lightweight fuzzy-search library, with zero dependencies
MIT License
934 stars 112 forks source link

Fatal error: Can't form Range with upperBound < lowerBound #36

Open el-quick opened 4 years ago

el-quick commented 4 years ago

I am trying use asynchronous version on this way:

fuse.search(searchText, in: Keyword.searchables, completion: { results in
    ...
})

And I am getting this problem:

Captura de Pantalla 2019-12-17 a la(s) 09 32 21

To take in account: Keyword.searchables is an array of string with near of 3000 items in it.

By the moment I solved it on this way:

for (index, item) in chunk.enumerated() {
    if let result = self.search(pattern, in: item) {
        if result.ranges.allSatisfy({ $0.upperBound > $0.lowerBound }) {
            items.append((index, result.score, result.ranges))
        }
    }
}

I know that's not the best way, and functionality comes affected, but it's working for me now.

Thanks in advance.