Manually tokenize search terms and emoji indexes
parent
5e0dc3bf63
commit
19eea428b8
|
@ -11,27 +11,41 @@ export default class Search extends React.Component {
|
||||||
|
|
||||||
buildIndex() {
|
buildIndex() {
|
||||||
this.index = lunr(function() {
|
this.index = lunr(function() {
|
||||||
|
this.pipeline.reset()
|
||||||
|
|
||||||
this.field('short_name', { boost: 2 })
|
this.field('short_name', { boost: 2 })
|
||||||
this.field('name')
|
this.field('name')
|
||||||
|
|
||||||
this.ref('short_name')
|
this.ref('id')
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let emoji in data.emojis) {
|
for (let emoji in data.emojis) {
|
||||||
let emojiData = data.emojis[emoji],
|
let emojiData = data.emojis[emoji],
|
||||||
{ short_name, name } = emojiData
|
{ short_name, name } = emojiData
|
||||||
|
|
||||||
this.index.add({ short_name, name })
|
this.index.add({
|
||||||
|
id: short_name,
|
||||||
|
short_name: this.tokenize(short_name),
|
||||||
|
name: this.tokenize(name),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tokenize (string) {
|
||||||
|
if (['-', '-1', '+', '+1'].indexOf(string) == 0) {
|
||||||
|
return string.split('')
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.split(/[-|_|\s]+/)
|
||||||
|
}
|
||||||
|
|
||||||
handleChange() {
|
handleChange() {
|
||||||
var { input } = this.refs,
|
var { input } = this.refs,
|
||||||
value = input.value,
|
value = input.value,
|
||||||
results = null
|
results = null
|
||||||
|
|
||||||
if (value.length) {
|
if (value.length) {
|
||||||
results = this.index.search(value).map((result) =>
|
results = this.index.search(this.tokenize(value)).map((result) =>
|
||||||
result.ref
|
result.ref
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue