|
@@ -58,13 +58,17 @@ public class TitleSimilarCheckUtil {
|
|
|
if (titleA.isEmpty() || titleB.isEmpty()) {
|
|
|
return false;
|
|
|
}
|
|
|
- int commonCount = 0;
|
|
|
- for (Character c : titleA) {
|
|
|
- if (titleB.contains(c)) {
|
|
|
- commonCount++;
|
|
|
+ // 确保遍历较小的集合以优化性能
|
|
|
+ Set<Character> smaller = titleA.size() < titleB.size() ? titleA : titleB;
|
|
|
+ Set<Character> larger = titleA.size() < titleB.size() ? titleB : titleA;
|
|
|
+
|
|
|
+ int intersectionCount = 0;
|
|
|
+ for (Character c : smaller) {
|
|
|
+ if (larger.contains(c)) {
|
|
|
+ intersectionCount++;
|
|
|
}
|
|
|
}
|
|
|
- double rate = commonCount / (double) Math.min(titleA.size(), titleB.size());
|
|
|
+ double rate = intersectionCount / (double) smaller.size();
|
|
|
return rate >= threshold;
|
|
|
}
|
|
|
|