Commit dc147398 authored by fallenstardust's avatar fallenstardust

模糊匹配关键词所相关的字段名称

parent 1cda9341
...@@ -81,7 +81,7 @@ public class CardKeyWord { ...@@ -81,7 +81,7 @@ public class CardKeyWord {
//包含系列,或者包含名字、描述 //包含系列,或者包含名字、描述
public NameFilter(@NonNull String word, boolean exclude, boolean onlyText) { public NameFilter(@NonNull String word, boolean exclude, boolean onlyText) {
this.setcode = onlyText ? 0 : DataManager.get().getStringManager().getSetCode(word); this.setcode = onlyText ? 0 : DataManager.get().getStringManager().getSetCode(word, true);
this.exclude = exclude; this.exclude = exclude;
this.word = word.toLowerCase(Locale.US); this.word = word.toLowerCase(Locale.US);
if(this.setcode > 0){ if(this.setcode > 0){
......
...@@ -410,7 +410,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder { ...@@ -410,7 +410,7 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
private List<Card> queryList(String keyword) { private List<Card> queryList(String keyword) {
// 获取关键词对应的 setcode // 获取关键词对应的 setcode
long setcode = DataManager.get().getStringManager().getSetCode(keyword); long setcode = DataManager.get().getStringManager().getSetCode(keyword, true);
// 从 cardManager 获取所有卡片 // 从 cardManager 获取所有卡片
SparseArray<Card> cards = cardManager.getAllCards(); SparseArray<Card> cards = cardManager.getAllCards();
if (cards == null) { if (cards == null) {
......
...@@ -202,13 +202,20 @@ public class StringManager implements Closeable { ...@@ -202,13 +202,20 @@ public class StringManager implements Closeable {
return String.format("0x%x", key); return String.format("0x%x", key);
} }
public long getSetCode(String key) { public long getSetCode(String key, boolean fuzzy) {
for (int i = 0; i < mCardSets.size(); i++) { for (int i = 0; i < mCardSets.size(); i++) {
CardSet cardSet = mCardSets.get(i); CardSet cardSet = mCardSets.get(i);
String[] setNames = cardSet.getName().split("\\|"); String[] setNames = cardSet.getName().split("\\|");
if (setNames[0].equalsIgnoreCase(key)) { if (fuzzy) {
return cardSet.getCode(); if (setNames[0].contains(key)) {
return cardSet.getCode();
}
} else {
if (setNames[0].equalsIgnoreCase(key)) {
return cardSet.getCode();
}
} }
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment