19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.Comparator;
24 import java.util.Optional;
25 import org.apache.commons.lang3.StringUtils;
38 class KeywordHit
implements Comparable<KeywordHit> {
40 private static final String GET_CONTENT_ID_FROM_ARTIFACT_ID =
"SELECT obj_id FROM blackboard_artifacts WHERE artifact_id = ";
42 private final long solrObjectId;
43 private final int chunkId;
44 private final String snippet;
45 private final String hit;
58 KeywordHit(String solrDocumentId, String snippet, String hit) {
59 this.snippet = StringUtils.stripToEmpty(snippet);
71 String[] split = solrDocumentId.split(Server.CHUNK_ID_SEPARATOR);
72 if (split.length == 1) {
74 this.solrObjectId = Long.parseLong(solrDocumentId);
77 this.solrObjectId = Long.parseLong(split[0]);
78 this.chunkId = Integer.parseInt(split[1]);
86 String getSolrDocumentId() {
87 return Long.toString(solrObjectId) + Server.CHUNK_ID_SEPARATOR + Long.toString(chunkId);
90 long getSolrObjectId() {
91 return this.solrObjectId;
98 boolean hasSnippet() {
99 return StringUtils.isNotBlank(this.snippet);
102 String getSnippet() {
117 long getContentID() throws TskCoreException {
118 if (isArtifactHit()) {
120 SleuthkitCase caseDb;
122 caseDb = Case.getOpenCase().getSleuthkitCase();
123 }
catch (NoCurrentCaseException ex) {
124 throw new TskCoreException(
"Exception while getting open case.", ex);
126 try (SleuthkitCase.CaseDbQuery executeQuery =
127 caseDb.executeQuery(GET_CONTENT_ID_FROM_ARTIFACT_ID +
this.solrObjectId);
128 ResultSet resultSet = executeQuery.getResultSet();) {
129 if (resultSet.next()) {
130 return resultSet.getLong(
"obj_id");
132 throw new TskCoreException(
"Failed to get obj_id for artifact with artifact_id =" + this.solrObjectId +
". No matching artifact was found.");
134 }
catch (SQLException ex) {
135 throw new TskCoreException(
"Error getting obj_id for artifact with artifact_id =" + this.solrObjectId, ex);
139 return this.solrObjectId;
148 boolean isArtifactHit() {
150 return this.solrObjectId < 0;
158 Optional<Long> getArtifactID() {
159 if (isArtifactHit()) {
160 return Optional.of(solrObjectId);
162 return Optional.empty();
167 public boolean equals(Object obj) {
171 if (getClass() != obj.getClass()) {
174 final KeywordHit other = (KeywordHit) obj;
175 return this.compareTo(other) == 0;
179 public int hashCode() {
181 hash = 41 * hash + (int) this.solrObjectId + this.chunkId;
186 public int compareTo(KeywordHit o) {
187 return Comparator.comparing(KeywordHit::getSolrObjectId)
188 .thenComparing(KeywordHit::getChunkId)