Giter VIP home page Giter VIP logo

fuse-swift's Introduction

Hi there 👋

fuse-swift's People

Contributors

abiaad avatar chuganzy avatar crtgregoric avatar gravicle avatar krisk avatar ludoded avatar maxxfrazer avatar nicoeg avatar peteraisher avatar schmidtyapps avatar stevensorial avatar wearhere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fuse-swift's Issues

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

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.

Did not work while searching in [Fuseable]

Here is my implementation. it always succeeds while checking if !item.responds(to: Selector(property.name))

extension Member: Fuseable { var properties: [FuseProperty] { return [ FuseProperty(name: name ?? ""), FuseProperty(name: phone ?? "") ] } }

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { guard searchText.count > 0 else { self.displayedMembers = self.allMembers self.membersTableView.reloadData() return } self.displayedMembers = searchEngine.search(searchText, in: self.allMembers).map { self.allMembers[$0.index] } self.membersTableView.reloadData() }

Swift 5 Support w/ Cocoapods

Expected Results

No warning to convert Fuse.framework to Swift 5

Actual Results

Xcode created warnings to convert Fuse.framework to Swift 5

Steps to Reproduce

Build the cocoapod in Xcode 10.2

Example 3 not working?

Hi,

it seems that Example 3 with search in Fusable is not working? The results is always empty?
I tried installing from github both the latest version and from "c7adb16" as mentioned in issue 40, but still there is no printout happening.

Treat words in query as individual queries for more exact results

First off, thanks for this awesome search library! I love it! ❤️

Say, I have an array of strings:

var array: [String] = ["Hello World", "Testing", "123 Hi"]

If I put fuse.search("hello", in: array), Fuse finds the first string, being "Hello World".
Same result when searching for "hello world", "lo wo", or "world".

However, when searching "world hello", Fuse does not find "Hello World", but I feel like it should.

Can we make it so the words in the search query are being treated as individual queries rather than one string?
(I'm sorry if this feature already exists and I missed it!)

Range<Index> init issue

In the latest Xcode 10, there is an issue with Range initializer, which corresponds to new changes in Swift 4.2

2018-06-05 14 28 28

Fuseable FuseProperty.name reports the value rather than the key

When using Fuseable protocol, the key to be searched is replaced with the value at runtime. The README indicates the expected report will contain the name of the property, not the value. The example code is passing in the value of each property at runtime. Using a string "key" instead will pass the string characters of the key (name) as the searchable text.

expected results:
matchedItem.results: [(key: "title", score: 0.027999999999999997, ranges: [CountableClosedRange(4...6)])]

actual results:
matchedItem.results: [(key: "Old Man\'s War fiction", score: 0.027999999999999997, ranges: [ClosedRange(4...6)])]

`
import XCTest
import Fuse

class FuseTests: XCTestCase {

struct Book: Fuseable {
              
    let author: String
    let title: String

    var properties: [FuseProperty] {
        return [
            FuseProperty(name: title, weight: 0.3),
            FuseProperty(name: author, weight: 0.7),
        ]
    }
}

override func setUp() {
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testFuseable() {
    
    let books: [Book] = [
        Book(author: "John X", title: "Old Man's War fiction"),
        Book(author: "P.D. Mans", title: "Right Ho Jeeves")
    ]
    
    let fuse = Fuse()
    
    let results = fuse.search("man", in: books)

    results.forEach { item in
        print("-- Fuse Result -----")
        print("index: \(item.index)")
        print("score: \(item.score)")
        print("results: \(item.results)")
        print("--------------------")
    }
    
    // Expected Output:
    // ...
    // index: 0
    // score: 0.028
    // results: [(key: "title", score: 0.027999999999999997, ranges: [CountableClosedRange(4...6)])]
    // ...
    
    // Actual Output
    
    // ...
    // index: 0
    // score: 0.027999999999999997
    // results: [(key: "Old Man\'s War fiction", score: 0.027999999999999997, ranges: [ClosedRange(4...6)])]
    // ...
    
    XCTAssertEqual(results[0].results[0].key, "author")
    
    
    
}

}

`

Latest Cocoapod Podspec

The podspec is out of date with what is available and fixed on master. Can you push a new version to cocoapods.

Thanks!

Best match

Hi kirsk,

Congrats for this excellent library.

One suggestion that maybe you could implement on the library.

Sometimes we need to find the best match, and only the best match on the string. One example. If we try to find "Hello World." inside "Hellu Wo** round" (returned by OCR) the result´s ranges include "Hell","Wo","r" and "d". It could be really interesting if fuze could return only the best match according to a character distance. For example.

Best Match with distance of 1 character: "Hell_ Wo" (range 0..7) and "r" and "d" would not be included in the result as they are more than one character far away from the best match.

Another example "Hellu Wuid" could return "Hell_ W__d" (range 0..9) with a character distance of 2 characters and "Hell_ W" with a distance of 1 character.

This porperty could make fuze really really a gem for OCR result´s processing.

Thanks in advance.

Search through an array of Fuseable objects with a value that is an array

Hi there! This is an awesome project, thank you for your hard work. I've used Fuse in the past in the JavaScript world and have found a need for it in Swift, so I'm excited to use this.

I'm trying to find a way to include a FuseProperty that is an array of keywords. However, Fuse doesn't seem to acknowledge the key if it holds an array opposed to a string. Here is the code that I have:

import Cocoa

class Book: Fuseable {
    @objc dynamic var name: String
    @objc dynamic var author: String
    @objc dynamic var keywords: [String] // <- This value doesn't seem to make a different
    
    init(author: String, name: String, keywords: [String]) {
        self.author = author
        self.name = name
        self.keywords = keywords
    }
    
    var properties: [FuseProperty] {
        return [
            FuseProperty(name: "name", weight: 0.3),
            FuseProperty(name: "author", weight: 0.2),
            FuseProperty(name: "keywords", weight: 0.5) // <- Not included in the results
        ]
    }
}

var books = [Book]()

let fuse = Fuse()

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        books.append(Book(author: "John X", name: "Old Man's War fiction", keywords: ["Testing 1", "Testing 2"]))
        books.append(Book(author: "P.D. Mans", name: "Right Ho Jeeves", keywords: ["Testing 3", "Testing 4"]))
        
        let results = fuse.search("man", in: books)
        
        for result in results {
            print(result)
        }

        // Do any additional setup after loading the view.
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}

Is this supported in fuse-swift?

MacOS Support

It would be neat if MacOS was supported. Current output when attempting to install via Cocoapods:

[!] The platform of the target `<target name>` (macOS 10.12) is not compatible with `Fuse (1.1.0)`, which does not support `osx`.

Fuse can't find exact match in longer sting

In this operation, Fuse is given a pattern

pattern = neighbours

And a string

content = Mr and Mrs Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much. They were the last people you’d expect to be involved in anything strange or mysterious, because they just didn’t hold with such nonsense. Mr Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large moustache. Mrs Dursley was thin and blonde and had nearly twice the usual amount of neck, which came in very useful as she spent so much of her time craning over garden fences, spying on the neighbours

However despite there being an exact match, the operation fails.

Fuse().search(pattern, in: content) //Produces nil

I'm using the blocking version of search, and would like to continue to do so if possible.

Appreciate any help, thanks!

CountableRange is coming one char short

When using the returned CountableRange<Int> values to create attributed strings, highlights come a char short. For example:

let options = ["active", "inactive", "canceled"]
let query = "act"
let results = fuse.search(query, in: options)

Results: (0, [0..<2]) & (1, [2..<4])
Expected results: (0, [0...2]) & (1, [2...4])

In my understanding search should be returning CountableClosedRanges, instead of half-closed CountbleRanges.

The example project would have the same issue, if it were not for the <= comparison in offset <= range.endIndex. This essentially treats the half-closed range as a closed range.

Put Package.swift in latest release

Recently Swift Package Manager is integrated into Xcode and it requires each tag to have Package.swift file. Release a new version (like 1.2.1) will be great.

String Comparison Crash

Hi,

Is there any reason why the below line of string comparison would lead to a crash?

    let result = fuse.search("Rancheras 2016 Borracho de Amor  Por Tu Maldito Amor  Hermoso Carino  Se Va Muriendo Mi Alma  Por un Amor", in: "Borracho De Amor")

fuse - comparison

fuse - crash

Any help would be appreciated. Thanks!

Best practices around reusing `Fuse` objects?

If I repeatedly search over similar datasets with the same parameters, I wonder if I should use the same Fuse object for all searches:

let fuse = Fuse()

func search() {
  return fuse.search...
}

vs. using a new Fuse object for every search

func search() {
  return Fuse().search...
}

Of particular concern to me is that I am using the async APIs which rely on per-instance dispatch queues. I kind of like the idea of using a new Fuse object for every search so that the searches don't "compete" on the same dispatch queue, but I don't know if there's actually any limit to concurrency per-custom-queue (as opposed to at the level of the global queues that back these custom queues, or eventually at the level where the work items are scheduled on threads, in which case different Fuse objects would be competing anyway).

I also don't know if there's overhead to having many custom dispatch queues, in which case it would be better to reuse one Fuse object. This Stack Overflow makes it seem like this wouldn't be a problem.

MacOS Support for Carthage

Hi there! I was curious if it would be possible for the framework to support MacOS through Carthage? Currently it only builds to IOS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.