mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
use initial snippet if available
This commit is contained in:
parent
5a8163236f
commit
30a3d007b7
@ -27,6 +27,7 @@ import java.util.Set;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.netbeans.api.progress.ProgressHandle;
|
import org.netbeans.api.progress.ProgressHandle;
|
||||||
import org.netbeans.api.progress.aggregate.ProgressContributor;
|
import org.netbeans.api.progress.aggregate.ProgressContributor;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
@ -46,7 +47,7 @@ import org.sleuthkit.datamodel.Content;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class QueryResults {
|
class QueryResults {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(QueryResults.class.getName());
|
private static final Logger logger = Logger.getLogger(QueryResults.class.getName());
|
||||||
private static final String MODULE_NAME = KeywordSearchModuleFactory.getModuleName();
|
private static final String MODULE_NAME = KeywordSearchModuleFactory.getModuleName();
|
||||||
/**
|
/**
|
||||||
@ -64,12 +65,12 @@ class QueryResults {
|
|||||||
*/
|
*/
|
||||||
// TODO: This is redundant. The keyword list is in the query.
|
// TODO: This is redundant. The keyword list is in the query.
|
||||||
private final KeywordList keywordList;
|
private final KeywordList keywordList;
|
||||||
|
|
||||||
QueryResults(KeywordSearchQuery query, KeywordList keywordList) {
|
QueryResults(KeywordSearchQuery query, KeywordList keywordList) {
|
||||||
this.keywordSearchQuery = query;
|
this.keywordSearchQuery = query;
|
||||||
this.keywordList = keywordList;
|
this.keywordList = keywordList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addResult(Keyword keyword, List<KeywordHit> hits) {
|
void addResult(Keyword keyword, List<KeywordHit> hits) {
|
||||||
results.put(keyword, hits);
|
results.put(keyword, hits);
|
||||||
}
|
}
|
||||||
@ -78,15 +79,15 @@ class QueryResults {
|
|||||||
KeywordList getKeywordList() {
|
KeywordList getKeywordList() {
|
||||||
return keywordList;
|
return keywordList;
|
||||||
}
|
}
|
||||||
|
|
||||||
KeywordSearchQuery getQuery() {
|
KeywordSearchQuery getQuery() {
|
||||||
return keywordSearchQuery;
|
return keywordSearchQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<KeywordHit> getResults(Keyword keyword) {
|
List<KeywordHit> getResults(Keyword keyword) {
|
||||||
return results.get(keyword);
|
return results.get(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Keyword> getKeywords() {
|
Set<Keyword> getKeywords() {
|
||||||
return results.keySet();
|
return results.keySet();
|
||||||
}
|
}
|
||||||
@ -112,7 +113,7 @@ class QueryResults {
|
|||||||
progress.start(getKeywords().size());
|
progress.start(getKeywords().size());
|
||||||
}
|
}
|
||||||
int unitProgress = 0;
|
int unitProgress = 0;
|
||||||
|
|
||||||
for (final Keyword keyword : getKeywords()) {
|
for (final Keyword keyword : getKeywords()) {
|
||||||
if (worker.isCancelled()) {
|
if (worker.isCancelled()) {
|
||||||
logger.log(Level.INFO, "Cancel detected, bailing before new keyword processed: {0}", keyword.getSearchTerm()); //NON-NLS
|
logger.log(Level.INFO, "Cancel detected, bailing before new keyword processed: {0}", keyword.getSearchTerm()); //NON-NLS
|
||||||
@ -130,20 +131,22 @@ class QueryResults {
|
|||||||
}
|
}
|
||||||
subProgress.progress(keywordList.getName() + ": " + hitDisplayStr, unitProgress);
|
subProgress.progress(keywordList.getName() + ": " + hitDisplayStr, unitProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (KeywordHit hit : getOneHitPerObject(keyword)) {
|
for (KeywordHit hit : getOneHitPerObject(keyword)) {
|
||||||
String termString = keyword.getSearchTerm();
|
String termString = keyword.getSearchTerm();
|
||||||
final String snippetQuery = KeywordSearchUtil.escapeLuceneQuery(termString);
|
final String snippetQuery = KeywordSearchUtil.escapeLuceneQuery(termString);
|
||||||
String snippet;
|
String snippet = hit.getSnippet();
|
||||||
try {
|
if (StringUtils.isBlank(snippet)) {
|
||||||
snippet = LuceneQuery.querySnippet(snippetQuery, hit.getSolrObjectId(), hit.getChunkId(), !keywordSearchQuery.isLiteral(), true);
|
try {
|
||||||
} catch (NoOpenCoreException e) {
|
snippet = LuceneQuery.querySnippet(snippetQuery, hit.getSolrObjectId(), hit.getChunkId(), !keywordSearchQuery.isLiteral(), true);
|
||||||
logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e); //NON-NLS
|
} catch (NoOpenCoreException e) {
|
||||||
//no reason to continue
|
logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e); //NON-NLS
|
||||||
break;
|
//no reason to continue
|
||||||
} catch (Exception e) {
|
break;
|
||||||
logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e); //NON-NLS
|
} catch (Exception e) {
|
||||||
continue;
|
logger.log(Level.WARNING, "Error querying snippet: " + snippetQuery, e); //NON-NLS
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (snippet != null) {
|
if (snippet != null) {
|
||||||
KeywordCachedArtifact writeResult = keywordSearchQuery.writeSingleFileHitsToBlackBoard(termString, hit, snippet, keywordList.getName());
|
KeywordCachedArtifact writeResult = keywordSearchQuery.writeSingleFileHitsToBlackBoard(termString, hit, snippet, keywordList.getName());
|
||||||
@ -166,11 +169,11 @@ class QueryResults {
|
|||||||
//group artifacts by type
|
//group artifacts by type
|
||||||
.collect(Collectors.groupingBy(BlackboardArtifact::getArtifactTypeID))
|
.collect(Collectors.groupingBy(BlackboardArtifact::getArtifactTypeID))
|
||||||
//for each type send an event
|
//for each type send an event
|
||||||
.forEach((typeID, artifacts) ->
|
.forEach((typeID, artifacts)
|
||||||
IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent(MODULE_NAME, BlackboardArtifact.ARTIFACT_TYPE.fromID(typeID), artifacts)));
|
-> IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent(MODULE_NAME, BlackboardArtifact.ARTIFACT_TYPE.fromID(typeID), artifacts)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newArtifacts;
|
return newArtifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +186,7 @@ class QueryResults {
|
|||||||
* SolrObjectID-ChunkID pairs.
|
* SolrObjectID-ChunkID pairs.
|
||||||
*/
|
*/
|
||||||
private Collection<KeywordHit> getOneHitPerObject(Keyword keyword) {
|
private Collection<KeywordHit> getOneHitPerObject(Keyword keyword) {
|
||||||
|
|
||||||
HashMap<Long, KeywordHit> hits = new HashMap<>();
|
HashMap<Long, KeywordHit> hits = new HashMap<>();
|
||||||
|
|
||||||
// create a list of KeywordHits. KeywordHits with lowest chunkID is added the the list.
|
// create a list of KeywordHits. KeywordHits with lowest chunkID is added the the list.
|
||||||
@ -206,7 +209,7 @@ class QueryResults {
|
|||||||
private void writeSingleFileInboxMessage(KeywordCachedArtifact written, Content hitContent) {
|
private void writeSingleFileInboxMessage(KeywordCachedArtifact written, Content hitContent) {
|
||||||
StringBuilder subjectSb = new StringBuilder();
|
StringBuilder subjectSb = new StringBuilder();
|
||||||
StringBuilder detailsSb = new StringBuilder();
|
StringBuilder detailsSb = new StringBuilder();
|
||||||
|
|
||||||
if (!keywordSearchQuery.isLiteral()) {
|
if (!keywordSearchQuery.isLiteral()) {
|
||||||
subjectSb.append(NbBundle.getMessage(this.getClass(), "KeywordSearchIngestModule.regExpHitLbl"));
|
subjectSb.append(NbBundle.getMessage(this.getClass(), "KeywordSearchIngestModule.regExpHitLbl"));
|
||||||
} else {
|
} else {
|
||||||
@ -270,5 +273,5 @@ class QueryResults {
|
|||||||
|
|
||||||
IngestServices.getInstance().postMessage(IngestMessage.createDataMessage(MODULE_NAME, subjectSb.toString(), detailsSb.toString(), uniqueKey, written.getArtifact()));
|
IngestServices.getInstance().postMessage(IngestMessage.createDataMessage(MODULE_NAME, subjectSb.toString(), detailsSb.toString(), uniqueKey, written.getArtifact()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user