在swift中运行flexsearch

0yg35tkg  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(227)

我创建了一个使用flexsearch的网站,但仅创建和编码部分,如下所示。

const flexSearch = await import('flexsearch')

const index = flexSearch.default.create({
    profile: 'match',
    encode: 'extra',
    tokenize: 'forward',
}).encode(rawString)

现在,我的任务是将此功能带到我们的swift ios应用程序中。首先,我下载了flesearch库并将其放入我们的ios应用程序项目中,并将其命名为flexsearchlight.js。下面是我在swift中尝试过的代码。我不确定如何将这些参数传递给swift中的create方法。

import JavaScriptCore

var jsContext = JSContext()

    if let jsSourcePath = Bundle.main.path(forResource: "flexsearchLight", ofType: "js") {
        do {

            // Load its contents to a String variable.
            let jsSourceContents = try String(contentsOfFile: jsSourcePath)

            // Add the Javascript code that currently exists in the jsSourceContents to the Javascript Runtime through the jsContext object.
            jsContext?.evaluateScript(jsSourceContents)

            let testFunction = jsContext?.objectForKeyedSubscript("create")
            let result = testFunction?.call(withArguments: [["profile": "match",
                                                             "encode": "extra",
                                                             "tokenize": "forward"]])

            print("result: \(String(describing: result))")
        }
        catch {
            print(error.localizedDescription)
        }
    }

任何帮助都将不胜感激

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题