Skip to content

Commit

Permalink
Fix chinese search (#1)
Browse files Browse the repository at this point in the history
* Fix minisearch Chinese search

per lucaong/minisearch#201 (comment)

* Mention feature in readme
  • Loading branch information
leverglowh authored Nov 21, 2024
1 parent 75444ff commit eb347f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ It literally copies all of the CSS from https://nitter.net so you should be able
use any of Nitter's [themes](https://github.com/zedeus/nitter/tree/master/public/css/themes). Just
copy the CSS file and replace `twitter.css` in the `index.html` with the theme
of your choice.

### Features

- Chinese tweet search optimization.
23 changes: 23 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ const app = Vue.createApp({
fields: ['full_text'], // fields to index for full-text search
storeFields: ['full_text', 'created_at', 'id_str', 'favorite_count', 'retweet_count'],
idField: 'id_str',
tokenize: (term) => {
if (typeof term === 'string') term = term.toLowerCase();
const segmenter = Intl.Segmenter && new Intl.Segmenter("zh", { granularity: "word" });
if (!segmenter) return [term];
const tokens = [];
for (const seg of segmenter.segment(term)) {
tokens.push(seg.segment);
}
return tokens;
},
searchOptions: {
combineWith: 'AND', // important for search chinese
processTerm: (term) => {
if (typeof term === 'string') term = term.toLowerCase();
const segmenter = Intl.Segmenter && new Intl.Segmenter("zh", { granularity: "word" });
if (!segmenter) return term;
const tokens = [];
for (const seg of segmenter.segment(term)) {
tokens.push(seg.segment);
}
return tokens;
},
},
});
this.miniSearch.addAll(this.tweets);
/* infinite scroll */
Expand Down

0 comments on commit eb347f8

Please sign in to comment.