keyword search: when done from GUI, use background thread to write results to BB not to block the GUI thread for huge queries

This commit is contained in:
adam-m 2012-02-15 12:33:18 -05:00
parent af4905a7dd
commit c6ce9575cf
2 changed files with 30 additions and 15 deletions

View File

@ -247,8 +247,10 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValue> {
int resID = 0; int resID = 0;
Collection<BlackboardArtifact> na = new ArrayList<BlackboardArtifact>(); final Collection<BlackboardArtifact> na = new ArrayList<BlackboardArtifact>();
for (FsContent f : fsContents) { final int numFsContents = fsContents.size();
int cur = 0;
for (final FsContent f : fsContents) {
//get unique match result files //get unique match result files
Map<String, Object> resMap = new LinkedHashMap<String, Object>(); Map<String, Object> resMap = new LinkedHashMap<String, Object>();
AbstractFsContentNode.fillPropertyMap(resMap, f); AbstractFsContentNode.fillPropertyMap(resMap, f);
@ -260,10 +262,18 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValue> {
toPopulate.add(new KeyValueContent(f.getName(), resMap, ++resID, f, highlightQueryEscaped)); toPopulate.add(new KeyValueContent(f.getName(), resMap, ++resID, f, highlightQueryEscaped));
//write to bb //write to bb
final boolean sendDataEvent = (cur == numFsContents-1?true:false);
new Thread() {
@Override
public void run() {
na.addAll(tcq.writeToBlackBoard(f)); na.addAll(tcq.writeToBlackBoard(f));
} if (sendDataEvent == true) {
//notify bb viewers
IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na)); IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na));
}
}
}.start();
cur++;
}
return true; return true;
} }

View File

@ -153,7 +153,7 @@ public class LuceneQuery implements KeywordSearchQuery {
@Override @Override
public void execute() { public void execute() {
escape(); escape();
List<FsContent> matches = performQuery(); final List<FsContent> matches = performQuery();
String pathText = "Keyword query: " + query; String pathText = "Keyword query: " + query;
@ -164,6 +164,9 @@ public class LuceneQuery implements KeywordSearchQuery {
searchResultWin.requestActive(); // make it the active top component searchResultWin.requestActive(); // make it the active top component
//write to bb //write to bb
new Thread() {
@Override
public void run() {
Collection<BlackboardArtifact> na = new ArrayList<BlackboardArtifact>(); Collection<BlackboardArtifact> na = new ArrayList<BlackboardArtifact>();
for (FsContent newHit : matches) { for (FsContent newHit : matches) {
na.addAll(writeToBlackBoard(newHit)); na.addAll(writeToBlackBoard(newHit));
@ -171,6 +174,8 @@ public class LuceneQuery implements KeywordSearchQuery {
//notify bb viewers //notify bb viewers
IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na)); IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na));
} }
}.start();
}
@Override @Override
public boolean validate() { public boolean validate() {