-
Notifications
You must be signed in to change notification settings - Fork 7
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
About Chinese Support #23
Comments
@chenhongen I should think this is more a flexsearch issue - have you tried checking out their docs? |
I find a issue in flexsearch about,and change my config to :
But,It doesn't work in neither Chinese nor English.It's a correct way to specify optional flexsearch configurations under a flexsearch key like this? |
@chenhongen Sorry for the delay on this, haven't had much spare time recently. I'm currently looking into a solution for this. |
@chenhongen I have just added support for a custom tokenize/encoder function, but it requires a bit of manual setup. Would you be able to test the below, and let me know if it works? Install Add this configuration in {
use: 'gridsome-plugin-flexsearch',
options: {
autoSetup: false
collections: [
{
typeName: 'ChePost',
indexName: 'ChePost',
fields: ['title', 'content', 'description']
}
],
searchFields: ['title', 'content', 'description'],
flexsearch: {
encode: false,
tokenize: function(str){
return str.replace(/[\x00-\x7F]/g, "").split("");
}
}
}
}, Then in your header/nav/search component, manually setup the flexsearch instance: <script>
import FlexSearch from 'flexsearch'
export default {
data: () => ({
searchTerm: '',
search: null
}),
computed: {
searchResults () {
const searchTerm = this.searchTerm
if (searchTerm.length < 3) return []
const results = this.search.search({ query: searchTerm, limit: 5, suggest: true })
console.log(results)
return results
}
},
async mounted () {
// Some flexsearch options, and helper functions
const { flexsearch, loadIndex } = this.$flexsearch
// Create a flexsearch instance, and load our config options, plus our custom tokenizer function
const search = new FlexSearch({
...flexsearch,
tokenize: function (str) {
return str.replace(/[\x00-\x7F]/g, '').split('')
}
})
// Make search available on this
this.search = search
// Load our index data into flexsearch
await loadIndex(search)
}
}
</script> |
Good job! Follow your steps,It works well~ thx |
To augment this (very helpful thread), I found a snippet of code that will make the flexsearch support both Latin alphabet (English) and CJK (Chinese) in the same search box: alex-shpak/hugo-book#80 (comment) Just apply it both in gridsome.config.js as well as in the search component in place of |
What happened
When I search in English keywords that title and content contain,It works well.But When I try Chinese,It didn't work.
Expected result
Support Chinese
Environment
gridsome: 0.7.12
gridsome-plugin-flexsearch:0.1.12
The text was updated successfully, but these errors were encountered: