Skip to content
This repository has been archived by the owner on May 8, 2022. It is now read-only.

Fuseable FuseProperty.name reports the value rather than the key #33

Open
levous opened this issue Dec 2, 2019 · 1 comment · May be fixed by #34 or #37
Open

Fuseable FuseProperty.name reports the value rather than the key #33

levous opened this issue Dec 2, 2019 · 1 comment · May be fixed by #34 or #37

Comments

@levous
Copy link

levous commented Dec 2, 2019

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")
    
    
    
}

}

`

@levous levous linked a pull request Dec 2, 2019 that will close this issue
@StevenSorial
Copy link
Contributor

This is a result of #20. I think its a semantics problem and the only change needed is to change FuseProperty's name to be value and FusableSearchResult's key to value.

@StevenSorial StevenSorial linked a pull request Dec 18, 2019 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants