Skip to content

Commit

Permalink
feat: search with traditional chinese
Browse files Browse the repository at this point in the history
add lib opencc4j
  • Loading branch information
isHarryh committed Jan 20, 2025
1 parent a43d795 commit b2d734d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ project(":core") {
api "apache-log4j:log4j:1.2.15"
// TiniPinyin
api 'com.github.promeg:tinypinyin:2.0.3'
// OpenCC4j
api 'com.github.houbb:opencc4j:1.8.1'
}
}
4 changes: 2 additions & 2 deletions core/src/cn/harryh/arkpets/assets/ModelItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public String getPinyinQuanpin() {
@JSONField(serialize = false)
public String getPinyinSuoxie() {
if (pinyinSuoxie == null) {
String quanpin = Pinyin.toPinyin(name, " ");
if (!quanpin.trim().isEmpty()) {
String quanpin = Pinyin.toPinyin(name, " ").trim();
if (!quanpin.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (String word : quanpin.split("\\s+")) {
builder.append(word.charAt(0));
Expand Down
3 changes: 2 additions & 1 deletion core/src/cn/harryh/arkpets/assets/ModelItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cn.harryh.arkpets.assets;

import cn.harryh.arkpets.assets.ModelItem.PropertyExtractor;
import com.github.houbb.opencc4j.util.ZhConverterUtil;

import java.util.*;
import java.util.function.Predicate;
Expand Down Expand Up @@ -45,7 +46,7 @@ public ModelItemGroup() {
public ModelItemGroup searchByKeyWords(String keyWords) {
if (keyWords == null || keyWords.isEmpty())
return this;
String[] wordList = keyWords.toUpperCase().split(" ");
String[] wordList = ZhConverterUtil.toSimple(keyWords).toUpperCase().split(" ");
ModelItemGroup result = new ModelItemGroup();

// Rule: match name
Expand Down

0 comments on commit b2d734d

Please sign in to comment.