Merge pull request #1729 from karlmortensen/getDocumentIdUpdate

Get document id update
This commit is contained in:
Richard Cordovano 2015-11-20 12:02:01 -05:00
commit 4d0a8df983
2 changed files with 40 additions and 17 deletions

View File

@ -36,6 +36,9 @@ import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.ContentVisitor;
import org.sleuthkit.datamodel.Directory;
import org.openide.util.Exceptions;
import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.BlackboardAttribute;
/**
* Displays the indexed text associated with a file or a blackboard artifact,
@ -257,21 +260,36 @@ public class ExtractedContentViewer implements DataContentViewer {
* @return The document ID or zero, which is an invalid document ID.
*/
private Long getDocumentId(Node node) {
/*
/**
* If the node is a Blackboard artifact node for anything other than a
* keyword hit, the document ID for the text extracted from the artifact
* (the concatenation of its attributes) is the artifact ID, a large,
* negative integer.
* negative integer. If it is a keyword hit, see if there is an
* associated artifact. If there is, get the associated artifact's ID
* and return it.
*/
BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
if (null != artifact && artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
return artifact.getArtifactID();
if (null != artifact) {
if (artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
return artifact.getArtifactID();
} else {
try {
// Get the associated artifact attribute and return its value as the ID
List<BlackboardAttribute> blackboardAttributes = artifact.getAttributes(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT);
if (!blackboardAttributes.isEmpty()) {
return blackboardAttributes.get(0).getValueLong();
}
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Error getting associated artifact attributes", ex); //NON-NLS
}
}
}
/*
* For keyword search hit artifact nodes and all other nodes, the
* document ID for the extracted text is the ID of the associated
* content, if any.
* content, if any, unless there is an associated artifact, which
* is handled above.
*/
Content content = node.getLookup().lookup(Content.class);
if (content != null) {

View File

@ -61,6 +61,7 @@ import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
import org.sleuthkit.autopsy.casemodule.Case.CaseType;
import org.sleuthkit.autopsy.coreutils.UNCPathUtilities;
@ -1020,7 +1021,7 @@ public class Server {
currentCoreLock.readLock().unlock();
}
}
/**
* Method to return ingester instance
*
@ -1129,7 +1130,7 @@ public class Server {
CoreAdminResponse response = CoreAdminRequest.getStatus(coreName, currentSolrServer);
Object dataDirPath = response.getCoreStatus(coreName).get("dataDir"); //NON-NLS
if (null != dataDirPath) {
File indexDir = Paths.get((String)dataDirPath, "index").toFile(); //NON-NLS
File indexDir = Paths.get((String) dataDirPath, "index").toFile(); //NON-NLS
return indexDir.exists();
} else {
return false;
@ -1234,16 +1235,20 @@ public class Server {
q.setFields(Schema.TEXT.toString());
try {
// Get the first result.
SolrDocument solrDocument = solrCore.query(q).getResults().get(0);
if (solrDocument != null) {
Collection<Object> fieldValues = solrDocument.getFieldValues(Schema.TEXT.toString());
if (fieldValues.size() == 1) // The indexed text field for artifacts will only have a single value.
{
return fieldValues.toArray(new String[0])[0];
} else // The indexed text for files has 2 values, the file name and the file content.
// We return the file content value.
{
return fieldValues.toArray(new String[0])[1];
SolrDocumentList solrDocuments = solrCore.query(q).getResults();
if (!solrDocuments.isEmpty()) {
SolrDocument solrDocument = solrDocuments.get(0);
if (solrDocument != null) {
Collection<Object> fieldValues = solrDocument.getFieldValues(Schema.TEXT.toString());
if (fieldValues.size() == 1) // The indexed text field for artifacts will only have a single value.
{
return fieldValues.toArray(new String[0])[0];
} else // The indexed text for files has 2 values, the file name and the file content.
// We return the file content value.
{
return fieldValues.toArray(new String[0])[1];
}
}
}
} catch (SolrServerException ex) {