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;
37 class KeywordHit
implements Comparable<KeywordHit> {
39 private static final String GET_CONTENT_ID_FROM_ARTIFACT_ID =
"SELECT obj_id FROM blackboard_artifacts WHERE artifact_id = ";
41 private final String solrDocumentId;
42 private final long solrObjectId;
43 private final int chunkId;
44 private final String snippet;
45 private final long contentID;
46 private final boolean hitOnArtifact;
47 private final String hit;
63 KeywordHit(String solrDocumentId, String snippet, String hit)
throws TskCoreException {
64 this.snippet = StringUtils.stripToEmpty(snippet);
66 this.solrDocumentId = solrDocumentId;
77 String[] split = solrDocumentId.split(Server.CHUNK_ID_SEPARATOR);
78 if (split.length == 1) {
80 this.solrObjectId = Long.parseLong(solrDocumentId);
83 this.solrObjectId = Long.parseLong(split[0]);
84 this.chunkId = Integer.parseInt(split[1]);
88 hitOnArtifact = this.solrObjectId < 0;
92 SleuthkitCase caseDb = Case.getCurrentCase().getSleuthkitCase();
93 try (SleuthkitCase.CaseDbQuery executeQuery =
94 caseDb.executeQuery(GET_CONTENT_ID_FROM_ARTIFACT_ID +
this.solrObjectId);
95 ResultSet resultSet = executeQuery.getResultSet();) {
96 if (resultSet.next()) {
97 contentID = resultSet.getLong(
"obj_id");
99 throw new TskCoreException(
"Failed to get obj_id for artifact with artifact_id =" + this.solrObjectId +
". No matching artifact was found.");
101 }
catch (SQLException ex) {
102 throw new TskCoreException(
"Error getting obj_id for artifact with artifact_id =" + this.solrObjectId, ex);
106 contentID = this.solrObjectId;
114 String getSolrDocumentId() {
115 return this.solrDocumentId;
118 long getSolrObjectId() {
119 return this.solrObjectId;
126 boolean hasSnippet() {
127 return StringUtils.isNotBlank(this.snippet);
130 String getSnippet() {
134 long getContentID() {
135 return this.contentID;
143 boolean isArtifactHit() {
144 return hitOnArtifact;
152 Optional<Long> getArtifactID() {
154 return Optional.of(solrObjectId);
156 return Optional.empty();
161 public boolean equals(Object obj) {
165 if (getClass() != obj.getClass()) {
168 final KeywordHit other = (KeywordHit) obj;
169 return this.compareTo(other) == 0;
173 public int hashCode() {
175 hash = 41 * hash + (int) this.solrObjectId + this.chunkId;
180 public int compareTo(KeywordHit o) {
181 return Comparator.comparing(KeywordHit::getSolrObjectId)
182 .thenComparing(KeywordHit::getChunkId)