Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordHit.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
26 
33 class KeywordHit implements Comparable<KeywordHit> {
34 
35  private final String solrDocumentId;
36  private final long solrObjectId;
37  private final int chunkId;
38  private final String snippet;
39  private final Content content;
40  private final BlackboardArtifact artifact;
41  private final String hit;
42 
43  public String getHit() {
44  return hit;
45  }
46 
47  KeywordHit(String solrDocumentId, String snippet) throws TskCoreException {
48  this(solrDocumentId, snippet, null);
49  }
50 
51  KeywordHit(String solrDocumentId, String snippet, String hit) throws TskCoreException {
55  this.solrDocumentId = solrDocumentId;
56 
66  final int separatorIndex = solrDocumentId.indexOf(Server.CHUNK_ID_SEPARATOR);
67  if (-1 != separatorIndex) {
68  this.solrObjectId = Long.parseLong(solrDocumentId.substring(0, separatorIndex));
69  this.chunkId = Integer.parseInt(solrDocumentId.substring(separatorIndex + 1));
70  } else {
71  this.solrObjectId = Long.parseLong(solrDocumentId);
72  this.chunkId = 0;
73  }
74 
80  SleuthkitCase caseDb = Case.getCurrentCase().getSleuthkitCase();
81  long fileId;
82  if (this.solrObjectId < 0) {
83  this.artifact = caseDb.getBlackboardArtifact(this.solrObjectId);
84  fileId = artifact.getObjectID();
85  } else {
86  this.artifact = null;
87  fileId = this.solrObjectId;
88  }
89  this.content = caseDb.getContentById(fileId);
90 
94  this.snippet = snippet;
95  this.hit = hit;
96  }
97 
98  String getSolrDocumentId() {
99  return this.solrDocumentId;
100  }
101 
102  long getSolrObjectId() {
103  return this.solrObjectId;
104  }
105 
106  boolean hasChunkId() {
107  return this.chunkId != 0;
108  }
109 
110  int getChunkId() {
111  return this.chunkId;
112  }
113 
114  boolean hasSnippet() {
115  return !this.snippet.isEmpty();
116  }
117 
118  String getSnippet() {
119  return this.snippet;
120  }
121 
122  Content getContent() {
123  return this.content;
124  }
125 
131  boolean isArtifactHit() {
132  return (null != this.artifact);
133  }
134 
141  BlackboardArtifact getArtifact() {
142  return this.artifact;
143  }
144 
145  @Override
146  public boolean equals(Object obj) {
147  if (null == obj) {
148  return false;
149  }
150  if (getClass() != obj.getClass()) {
151  return false;
152  }
153  final KeywordHit other = (KeywordHit) obj;
154  return (this.solrObjectId == other.solrObjectId && this.chunkId == other.chunkId);
155  }
156 
157  @Override
158  public int hashCode() {
159  int hash = 3;
160  hash = 41 * hash + (int) this.solrObjectId + this.chunkId;
161  return hash;
162  }
163 
164  @Override
165  public int compareTo(KeywordHit o) {
166  if (this.solrObjectId < o.solrObjectId) {
167  // Out object id is less than the other object id
168  return -1;
169  } else if (this.solrObjectId == o.solrObjectId) {
170  // Hits have same object id
171  if (this.chunkId < o.chunkId) {
172  // Our chunk id is lower than the other chunk id
173  return -1;
174  } else {
175  // Our chunk id is either greater than or equal to the other chunk id
176  return this.chunkId == o.chunkId ? 0 : 1;
177  }
178  } else {
179  // Our object id is greater than the other object id
180  return 1;
181  }
182  }
183 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.