mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 16:06:15 +00:00
Cleanup KeywordHit.java
This commit is contained in:
parent
81e22212e8
commit
aadb79331f
@ -31,10 +31,13 @@ import org.sleuthkit.datamodel.TskCoreException;
|
|||||||
* Represents the fact that a file or an artifact associated with a file had a
|
* Represents the fact that a file or an artifact associated with a file had a
|
||||||
* keyword hit. All instances make both the document id of the Solr document
|
* keyword hit. All instances make both the document id of the Solr document
|
||||||
* where the keyword was found and the object Id of the file available to
|
* where the keyword was found and the object Id of the file available to
|
||||||
* clients. Artifact keyword hits also make the artifact available to clients.
|
* clients. Keyword hits on the indexed text of an artifact also make the
|
||||||
|
* artifact available to clients.
|
||||||
*/
|
*/
|
||||||
class KeywordHit implements Comparable<KeywordHit> {
|
class KeywordHit implements Comparable<KeywordHit> {
|
||||||
|
|
||||||
|
private static final String GET_CONTENT_ID_FROM_ARTIFACT_ID = "SELECT obj_id FROM blackboard_artifacts WHERE artifact_id = ";
|
||||||
|
|
||||||
private final String solrDocumentId;
|
private final String solrDocumentId;
|
||||||
private final long solrObjectId;
|
private final long solrObjectId;
|
||||||
private final int chunkId;
|
private final int chunkId;
|
||||||
@ -43,41 +46,52 @@ class KeywordHit implements Comparable<KeywordHit> {
|
|||||||
private final boolean hitOnArtifact;
|
private final boolean hitOnArtifact;
|
||||||
private final String hit;
|
private final String hit;
|
||||||
|
|
||||||
public String getHit() {
|
/**
|
||||||
return hit;
|
* Constructor
|
||||||
}
|
*
|
||||||
|
* @param solrDocumentId The ID of the document this hit is in.
|
||||||
|
* @param snippet A small amount of text from the document containing
|
||||||
|
* the hit.
|
||||||
|
* @param hit The exact text from the document that was the hit.
|
||||||
|
* For some searches (ie substring,regex) this will be
|
||||||
|
* different than the search term.
|
||||||
|
*
|
||||||
|
* @throws TskCoreException If there is a problem getting the underlying
|
||||||
|
* content associated with a hit on the text of an
|
||||||
|
* artifact..
|
||||||
|
*/
|
||||||
KeywordHit(String solrDocumentId, String snippet, String hit) throws TskCoreException {
|
KeywordHit(String solrDocumentId, String snippet, String hit) throws TskCoreException {
|
||||||
this.snippet = StringUtils.stripToEmpty(snippet);
|
this.snippet = StringUtils.stripToEmpty(snippet);
|
||||||
this.hit = hit;
|
this.hit = hit;
|
||||||
this.solrDocumentId = solrDocumentId;
|
this.solrDocumentId = solrDocumentId;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Parse the Solr document id to get the Solr object id and chunk id.
|
* Parse the Solr document id to get the Solr object id and chunk id.
|
||||||
* The Solr object id will either be a file id or an artifact id from
|
* The Solr object id will either be the object id of a file id or an
|
||||||
* the case database.
|
* artifact id from the case database.
|
||||||
*
|
*
|
||||||
* For every object (file or artifact) there will at least two Solr
|
* For every object (file or artifact) there will at least two Solr
|
||||||
* documents. One contains object metadata (chunk #1) and the second and
|
* documents. One contains object metadata (chunk #1) and the second and
|
||||||
* subsequent documents contain chunks of the text.
|
* subsequent documents contain chunks of the text.
|
||||||
*/
|
*/
|
||||||
final int separatorIndex = solrDocumentId.indexOf(Server.CHUNK_ID_SEPARATOR);
|
String[] split = solrDocumentId.split(Server.CHUNK_ID_SEPARATOR);
|
||||||
if (-1 != separatorIndex) {
|
if (split.length == 1) {
|
||||||
this.solrObjectId = Long.parseLong(solrDocumentId.substring(0, separatorIndex));
|
//chunk 0 has only the bare document id without the chunk id.
|
||||||
this.chunkId = Integer.parseInt(solrDocumentId.substring(separatorIndex + 1));
|
|
||||||
} else {
|
|
||||||
this.solrObjectId = Long.parseLong(solrDocumentId);
|
this.solrObjectId = Long.parseLong(solrDocumentId);
|
||||||
this.chunkId = 0;
|
this.chunkId = 0;
|
||||||
|
} else {
|
||||||
|
this.solrObjectId = Long.parseLong(split[0]);
|
||||||
|
this.chunkId = Integer.parseInt(split[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//artifacts have negative obj ids
|
||||||
hitOnArtifact = this.solrObjectId < 0;
|
hitOnArtifact = this.solrObjectId < 0;
|
||||||
|
|
||||||
/*
|
|
||||||
* If the high order bit of the object id is set (ie, it is negative),
|
|
||||||
* the hit was in an artifact, look up the artifact.
|
|
||||||
*/
|
|
||||||
if (hitOnArtifact) {
|
if (hitOnArtifact) {
|
||||||
|
// If the hit was in an artifact, look up the artifact.
|
||||||
SleuthkitCase caseDb = Case.getCurrentCase().getSleuthkitCase();
|
SleuthkitCase caseDb = Case.getCurrentCase().getSleuthkitCase();
|
||||||
try (SleuthkitCase.CaseDbQuery executeQuery = caseDb.executeQuery("select obj_id from blackboard_artifacts where artifact_id = " + this.solrObjectId);
|
try (SleuthkitCase.CaseDbQuery executeQuery =
|
||||||
|
caseDb.executeQuery(GET_CONTENT_ID_FROM_ARTIFACT_ID + this.solrObjectId);
|
||||||
ResultSet resultSet = executeQuery.getResultSet();) {
|
ResultSet resultSet = executeQuery.getResultSet();) {
|
||||||
if (resultSet.next()) {
|
if (resultSet.next()) {
|
||||||
contentID = resultSet.getLong("obj_id");
|
contentID = resultSet.getLong("obj_id");
|
||||||
@ -93,6 +107,10 @@ class KeywordHit implements Comparable<KeywordHit> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getHit() {
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
|
||||||
String getSolrDocumentId() {
|
String getSolrDocumentId() {
|
||||||
return this.solrDocumentId;
|
return this.solrDocumentId;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user