do direct db query for contentID intead of getting the entire artifact.

This commit is contained in:
millmanorama 2017-09-07 16:38:33 +02:00
parent 55dd19b39c
commit 81e22212e8
2 changed files with 25 additions and 12 deletions

View File

@ -18,11 +18,12 @@
*/
package org.sleuthkit.autopsy.keywordsearch;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Comparator;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException;
@ -76,8 +77,16 @@ class KeywordHit implements Comparable<KeywordHit> {
*/
if (hitOnArtifact) {
SleuthkitCase caseDb = Case.getCurrentCase().getSleuthkitCase();
BlackboardArtifact artifact = caseDb.getBlackboardArtifact(this.solrObjectId);
contentID = artifact.getObjectID();
try (SleuthkitCase.CaseDbQuery executeQuery = caseDb.executeQuery("select obj_id from blackboard_artifacts where artifact_id = " + this.solrObjectId);
ResultSet resultSet = executeQuery.getResultSet();) {
if (resultSet.next()) {
contentID = resultSet.getLong("obj_id");
} else {
throw new TskCoreException("Failed to get obj_id for artifact with artifact_id =" + this.solrObjectId + ". No matching artifact was found.");
}
} catch (SQLException ex) {
throw new TskCoreException("Error getting obj_id for artifact with artifact_id =" + this.solrObjectId, ex);
}
} else {
//else the object id is for content.
contentID = this.solrObjectId;

View File

@ -186,16 +186,20 @@ class KeywordSearchResultFactory extends ChildFactory<KeyValueQueryContent> {
properties.put(TSK_KEYWORD_PREVIEW.getDisplayName(), hit.getSnippet());
}
try {
String hitName = hit.isArtifactHit()
? tskCase.getBlackboardArtifact(hit.getArtifactID().get()).getDisplayName() + " Artifact" //NON-NLS
: contentName;
hitNumber++;
tempList.add(new KeyValueQueryContent(hitName, properties, hitNumber, hit.getSolrObjectId(), content, queryRequest, queryResults));
} catch (TskCoreException ex) {
Exceptions.printStackTrace(ex);
return false;
String hitName;
if (hit.isArtifactHit()) {
try {
hitName = tskCase.getBlackboardArtifact(hit.getArtifactID().get()).getDisplayName() + " Artifact"; //NON-NLS
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Error getting blckboard artifact by id", ex);
return false;
}
} else {
hitName = contentName;
}
hitNumber++;
tempList.add(new KeyValueQueryContent(hitName, properties, hitNumber, hit.getSolrObjectId(), content, queryRequest, queryResults));
}
// Add all the nodes to toPopulate at once. Minimizes node creation