Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement search matching sort function? #252

Open
invious opened this issue Jun 28, 2018 · 1 comment
Open

How to implement search matching sort function? #252

invious opened this issue Jun 28, 2018 · 1 comment

Comments

@invious
Copy link

invious commented Jun 28, 2018

I have this function which

    _handleSort = (a, b, input_string) => {
        let distance = this.levenshtein.get(a.name, input_string) - this.levenshtein.get(b.name, input_string)
        console.log(`a:${a.name}, b:${b.name}, input:${input_string}`)
        return distance;
    }

How can I make it so that the results are sorted by this function as I type in the AsyncTypeAhead

@invious
Copy link
Author

invious commented Jun 28, 2018

something like this?

<AsyncTypeahead
                    onSearch={this._handleSearch}
                    searchOptions={this._handleSort}
    ...

_handleSort = (value, options) => {
        let sorter = (a, b) => {
            let distance = this.levenshtein.get(a.name, value) - this.levenshtein.get(b.name, value)
            console.log(`a:${a.name}, b:${b.name}, input:${value}`)
            return distance;
        }
        return options.sort(sorter)
    }

it doesn't seem like the sorter function is ever getting called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant