Skip to content
This repository was archived by the owner on May 8, 2022. It is now read-only.
This repository was 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

Description

@levous

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

}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions