Skip to content

Commit

Permalink
Merge pull request #2233 from sepinf-inc/#2232_FixCategoryCount
Browse files Browse the repository at this point in the history
Count items in parent categories and add to children's totals (#2232)
  • Loading branch information
lfcnassif committed Jun 18, 2024
2 parents a27e82c + 3928caa commit 7c4d1bc
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions iped-engine/src/main/java/iped/engine/data/IPEDSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,29 +421,27 @@ private int countNumItems(Category category) {
if (category.getNumItems() != -1)
return category.getNumItems();

if (!category.getChildren().isEmpty()) {
int num = 0;
for (Category child : category.getChildren()) {
num += countNumItems(child);
}
category.setNumItems(num);

} else {
String query = IndexItem.CATEGORY + ":\"" + category.getName() + "\"";
IPEDSearcher searcher = new IPEDSearcher(this, query);
searcher.setNoScoring(true);
try {
if (this instanceof IPEDMultiSource) {
category.setNumItems(searcher.multiSearch().getLength());
} else {
category.setNumItems(searcher.search().getLength());
}
int num = 0;
for (Category child : category.getChildren()) {
num += countNumItems(child);
}

} catch (Exception e) {
e.printStackTrace();
String query = IndexItem.CATEGORY + ":\"" + category.getName() + "\"";
IPEDSearcher searcher = new IPEDSearcher(this, query);
searcher.setNoScoring(true);
try {
if (this instanceof IPEDMultiSource) {
num += searcher.multiSearch().getLength();
} else {
num += searcher.search().getLength();
}

} catch (Exception e) {
e.printStackTrace();
}
return category.getNumItems();

category.setNumItems(num);
return num;
}

private void loadKeywords() {
Expand Down

0 comments on commit 7c4d1bc

Please sign in to comment.