Merge branch '2839-improve-keywor-hits-tree-speed' of github.com:millmanorama/autopsy into 2840_file_types_key

This commit is contained in:
esaunders 2017-07-24 13:55:42 -04:00
commit 6f18b9b5bd

View File

@ -24,7 +24,6 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -33,6 +32,7 @@ import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.openide.nodes.ChildFactory; import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children; import org.openide.nodes.Children;
@ -95,6 +95,10 @@ public class KeywordHits implements AutopsyVisitableItem {
+ " OR attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_REGEXP.getTypeID()//NON-NLS + " OR attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_REGEXP.getTypeID()//NON-NLS
+ ")"; //NON-NLS + ")"; //NON-NLS
static private boolean isOnlyDefaultInstance(List<String> instances) {
return (instances.size() == 1) && (instances.get(0).equals(DEFAULT_INSTANCE_NAME));
}
public KeywordHits(SleuthkitCase skCase) { public KeywordHits(SleuthkitCase skCase) {
this.skCase = skCase; this.skCase = skCase;
keywordResults = new KeywordResults(); keywordResults = new KeywordResults();
@ -265,7 +269,6 @@ public class KeywordHits implements AutopsyVisitableItem {
addRegExpToList(listMap, reg, word, id); addRegExpToList(listMap, reg, word, id);
} }
} else {//single term } else {//single term
if ("1".equals(kwType) || reg == null) { //literal, substring or exact if ("1".equals(kwType) || reg == null) { //literal, substring or exact
/* /*
* Substring, treated same as exact match. "1" is * Substring, treated same as exact match. "1" is
@ -626,9 +629,8 @@ public class KeywordHits implements AutopsyVisitableItem {
@Override @Override
public boolean isLeafTypeNode() { public boolean isLeafTypeNode() {
List<String> instances = keywordResults.getKeywordInstances(setName, keyword);
// is this an exact/substring match (i.e. did we use the DEFAULT name)? // is this an exact/substring match (i.e. did we use the DEFAULT name)?
return instances.size() == 1 && instances.get(0).equals(DEFAULT_INSTANCE_NAME); return isOnlyDefaultInstance(keywordResults.getKeywordInstances(setName, keyword));
} }
@Override @Override
@ -661,7 +663,6 @@ public class KeywordHits implements AutopsyVisitableItem {
return s; return s;
} }
} }
/** /**
@ -706,7 +707,6 @@ public class KeywordHits implements AutopsyVisitableItem {
private final String keyword; private final String keyword;
private final String setName; private final String setName;
private final Map<RegExpInstanceKey, DisplayableItemNode> nodesMap = new HashMap<>();
private RegExpInstancesFactory(String setName, String keyword) { private RegExpInstancesFactory(String setName, String keyword) {
super(); super();
@ -720,29 +720,20 @@ public class KeywordHits implements AutopsyVisitableItem {
// The keys are different depending on what we are displaying. // The keys are different depending on what we are displaying.
// regexp get another layer to show instances. // regexp get another layer to show instances.
// Exact/substring matches don't. // Exact/substring matches don't.
if ((instances.size() == 1) && (instances.get(0).equals(DEFAULT_INSTANCE_NAME))) { if (isOnlyDefaultInstance(instances)) {
for (Long id : keywordResults.getArtifactIds(setName, keyword, DEFAULT_INSTANCE_NAME)) { list.addAll(keywordResults.getArtifactIds(setName, keyword, DEFAULT_INSTANCE_NAME).stream()
RegExpInstanceKey key = new RegExpInstanceKey(id); .map(RegExpInstanceKey::new)
nodesMap.computeIfAbsent(key, k -> createNode(k)); .collect(Collectors.toList()));
list.add(key);
}
} else { } else {
for (String instance : instances) { list.addAll(instances.stream()
RegExpInstanceKey key = new RegExpInstanceKey(instance); .map(RegExpInstanceKey::new)
nodesMap.computeIfAbsent(key, k -> createNode(k)); .collect(Collectors.toList()));
list.add(key);
}
} }
return true; return true;
} }
@Override @Override
protected Node createNodeForKey(RegExpInstanceKey key) { protected Node createNodeForKey(RegExpInstanceKey key) {
return nodesMap.get(key);
}
private DisplayableItemNode createNode(RegExpInstanceKey key) {
if (key.isRegExp()) { if (key.isRegExp()) {
return new RegExpInstanceNode(setName, keyword, key.getRegExpKey()); return new RegExpInstanceNode(setName, keyword, key.getRegExpKey());
} else { } else {
@ -750,6 +741,7 @@ public class KeywordHits implements AutopsyVisitableItem {
return createBlackboardArtifactNode(key.getIdKey()); return createBlackboardArtifactNode(key.getIdKey());
} }
} }
} }
/** /**
@ -884,7 +876,6 @@ public class KeywordHits implements AutopsyVisitableItem {
private final String keyword; private final String keyword;
private final String setName; private final String setName;
private final String instance; private final String instance;
private final Map<Long, BlackboardArtifactNode> nodesMap = new HashMap<>();
private HitsFactory(String setName, String keyword, String instance) { private HitsFactory(String setName, String keyword, String instance) {
super(); super();
@ -895,16 +886,13 @@ public class KeywordHits implements AutopsyVisitableItem {
@Override @Override
protected boolean createKeys(List<Long> list) { protected boolean createKeys(List<Long> list) {
for (Long id : keywordResults.getArtifactIds(setName, keyword, instance)) { list.addAll(keywordResults.getArtifactIds(setName, keyword, instance));
nodesMap.computeIfAbsent(id, i -> createBlackboardArtifactNode(i));
list.add(id);
}
return true; return true;
} }
@Override @Override
protected Node createNodeForKey(Long artifactId) { protected Node createNodeForKey(Long artifactId) {
return nodesMap.get(artifactId); return createBlackboardArtifactNode(artifactId);
} }
} }
} }