From e78134ca37392cd2eaba397b9de3e4da10f059e6 Mon Sep 17 00:00:00 2001 From: adam-m Date: Thu, 5 Apr 2012 10:29:30 -0400 Subject: [PATCH] Single keyword search: make bb writes more efficient in a single background thread --- .../KeywordSearchResultFactory.java | 73 ++++++++----------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java index 40e68641d8..b379e48c6c 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/KeywordSearchResultFactory.java @@ -223,7 +223,7 @@ public class KeywordSearchResultFactory extends ChildFactory { //execute the query and get fscontents matching Map> tcqRes = tcq.performQuery(); - Set fsContents = new HashSet(); + final Set fsContents = new HashSet(); for (String key : tcqRes.keySet()) { fsContents.addAll(tcqRes.get(key)); } @@ -276,9 +276,7 @@ public class KeywordSearchResultFactory extends ChildFactory { final String theListName = listName; int resID = 0; - final Collection na = new ArrayList(); - final int numFsContents = fsContents.size(); - int cur = 0; + for (final FsContent f : fsContents) { //get unique match result files Map resMap = new LinkedHashMap(); @@ -289,24 +287,25 @@ public class KeywordSearchResultFactory extends ChildFactory { setCommonProperty(resMap, CommonPropertyTypes.CONTEXT, snippet); } toPopulate.add(new KeyValueQueryContent(f.getName(), resMap, ++resID, f, highlightQueryEscaped, tcq)); + } + //write to bb + new Thread() { - //write to bb - final boolean sendDataEvent = (cur == numFsContents - 1 ? true : false); //send a single bulk notification after the last write - new Thread() { - - @Override - public void run() { + @Override + public void run() { + final Collection na = new ArrayList(); + for (final FsContent f : fsContents) { Collection written = tcq.writeToBlackBoard(f, theListName); for (KeywordWriteResult w : written) { na.add(w.getArtifact()); } - if (sendDataEvent == true && !na.isEmpty()) { - IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na)); - } + } - }.start(); - cur++; - } + if (!na.isEmpty()) { + IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na)); + } + } + }.start(); return true; } @@ -377,36 +376,37 @@ public class KeywordSearchResultFactory extends ChildFactory { } //get unique match result files - Set uniqueMatches = new LinkedHashSet(); + final Set uniqueMatches = new LinkedHashSet(); uniqueMatches.addAll(matches); int resID = 0; - int cur = 0; + final KeywordSearchQuery origQuery = thing.getQuery(); - final int numFsContents = uniqueMatches.size(); - final Collection na = new ArrayList(); + for (final FsContent f : uniqueMatches) { Map resMap = new LinkedHashMap(); AbstractFsContentNode.fillPropertyMap(resMap, (File) f); toPopulate.add(new KeyValueQueryContent(f.getName(), resMap, ++resID, f, keywordQuery, thing.getQuery())); - //write to bb - final boolean sendDataEvent = (cur == numFsContents - 1 ? true : false); //send a single bulk notification after the last write - new Thread() { + } + //write to bb + new Thread() { - @Override - public void run() { + @Override + public void run() { + final Collection na = new ArrayList(); + for (final FsContent f : uniqueMatches) { Collection written = origQuery.writeToBlackBoard(f, ""); for (KeywordWriteResult w : written) { na.add(w.getArtifact()); } - if (sendDataEvent == true && !na.isEmpty()) { - IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na)); - } } - }.start(); - cur++; - } + if (!na.isEmpty()) { + IngestManager.fireServiceDataEvent(new ServiceDataEvent(KeywordSearchIngestService.MODULE_NAME, ARTIFACT_TYPE.TSK_KEYWORD_HIT, na)); + } + } + }.start(); + return true; } @@ -417,17 +417,6 @@ public class KeywordSearchResultFactory extends ChildFactory { final Content content = thingContent.getContent(); final String query = thingContent.getQueryStr(); - Core core = null; - try { - core = KeywordSearch.getServer().getCore(); - } catch (SolrServerException ex) { - logger.log(Level.INFO, "Could not get Solr core", ex); - } - if (core == null) { - return null; - } - - Node kvNode = new KeyValueNode(thingContent, Children.LEAF, Lookups.singleton(content)); //wrap in KeywordSearchFilterNode for the markup content HighlightedMatchesSource highlights = new HighlightedMatchesSource(content, query, !thingContent.getQuery().isEscaped());