Commit dd39a1bd authored by fallenstardust's avatar fallenstardust

关键词排除须"-"后有文本,单"-"不视为排除

添加注释
parent a24faf25
...@@ -21,44 +21,69 @@ public class CardKeyWord { ...@@ -21,44 +21,69 @@ public class CardKeyWord {
private final boolean empty; private final boolean empty;
public CardKeyWord(String word) { public CardKeyWord(String word) {
// 保存原始搜索关键词
this.word = word; this.word = word;
// 如果关键词不为空,则进行解析和过滤器构建
if (!TextUtils.isEmpty(word)) { if (!TextUtils.isEmpty(word)) {
if (TextUtils.isDigitsOnly(word) && word.length() >= 5) {
//搜索卡密 // 判断是否为纯数字且长度大于等于5,若是则作为卡密搜索
if (TextUtils.isDigitsOnly(word) && word.length() >= 3) {
// 添加卡密过滤器
filterList.add(new CodeFilter(Long.parseLong(word))); filterList.add(new CodeFilter(Long.parseLong(word)));
} else { } else {
// 按空格分割关键词
String[] ws = word.split(" "); String[] ws = word.split(" ");
// 如果设置中的关键词分割符是"%%",则重新分割
if (AppsSettings.get().getKeyWordsSplit() == AppsSettings.keyWordsSplitEnum.Percent.code) { if (AppsSettings.get().getKeyWordsSplit() == AppsSettings.keyWordsSplitEnum.Percent.code) {
ws = word.split("%%"); ws = word.split("%%");
} }
// 遍历每个分割后的关键词
for (String w : ws) { for (String w : ws) {
// 跳过空字符串
if (TextUtils.isEmpty(w)) { if (TextUtils.isEmpty(w)) {
continue; continue;
} }
// 初始化排除标记为false
boolean exclude = false; boolean exclude = false;
if (w.startsWith("-")) { // 如果关键词以"-"开头,则表示排除模式
if (w.startsWith("-") && w.length() > 1) {
exclude = true; exclude = true;
// 去掉"-"前缀
w = w.substring(1); w = w.substring(1);
} }
// 初始化仅文本标记为false(当前被注释掉的功能)
boolean onlyText = false; boolean onlyText = false;
/* /*
if (w.startsWith("\"") || w.startsWith("“") || w.startsWith("”")) { // 如果关键词以引号开头,则只搜索文本内容
//只搜索文字 if (w.startsWith("\"") || w.startsWith("“") || w.startsWith("”")) {
onlyText = true; // 设置仅文本标志
if (w.endsWith("\"") || w.endsWith("“") || w.endsWith("”")) { onlyText = true;
w = w.substring(1, w.length() - 1); // 如果也以引号结尾,则去掉首尾引号
} else { if (w.endsWith("\"") || w.endsWith("“") || w.endsWith("”")) {
w = w.substring(1); w = w.substring(1, w.length() - 1);
} } else {
}*/ // 否则只去掉开始的引号
w = w.substring(1);
}
}*/
// 记录当前过滤器参数的日志
Log.d(TAG, "filter:word=" + w + ", exclude=" + exclude + ", onlyText=" + onlyText); Log.d(TAG, "filter:word=" + w + ", exclude=" + exclude + ", onlyText=" + onlyText);
// 添加名称过滤器
filterList.add(new NameFilter(w, exclude, onlyText)); filterList.add(new NameFilter(w, exclude, onlyText));
} }
} }
} }
empty = filterList.size() == 0; // 判断是否有有效的过滤器
empty = filterList.isEmpty();
} }
public String getValue() { public String getValue() {
return word; return word;
} }
...@@ -85,7 +110,7 @@ public class CardKeyWord { ...@@ -85,7 +110,7 @@ public class CardKeyWord {
this.setcode = onlyText ? 0 : DataManager.get().getStringManager().getSetCode(word, true); 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) {
Log.d(TAG, "filter:setcode=" + setcode + ", exclude=" + exclude + ", word=" + word); Log.d(TAG, "filter:setcode=" + setcode + ", exclude=" + exclude + ", word=" + word);
} }
} }
......
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