mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 08:26:15 +00:00
Keyword search: Remove obsolete less writeToBlackBoard() from interface, use only the more efficient method.
Better error handling of Solr errors.
This commit is contained in:
parent
a2267f34f5
commit
dd309abbe0
@ -141,7 +141,8 @@ class HighlightedMatchesSource implements MarkupSource, HighlightLookup {
|
||||
return "<pre>" + highlightedContent + "</pre>";
|
||||
}
|
||||
} catch (SolrServerException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
logger.log(Level.INFO, "Could not query markup. ", ex);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,14 +77,6 @@ public interface KeywordSearchQuery {
|
||||
*/
|
||||
public Collection<Term>getTerms();
|
||||
|
||||
/**
|
||||
* write search results to blackboard
|
||||
* @param newFsHit new fscontent hit associated with the result to write to bb
|
||||
* @param listname list name with the keyword query, or null
|
||||
* @return collection of results (with cached bb artifacts/attributes) created and written
|
||||
*/
|
||||
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName);
|
||||
|
||||
/**
|
||||
* write results to blackboard per single term and file hit
|
||||
* this method is useful if something else should keep track of partial results to write
|
||||
|
@ -192,10 +192,6 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
|
||||
throw new UnsupportedOperationException("writeToBlackBoard() unsupported by manager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeywordWriteResult writeToBlackBoard(String termHit, FsContent newFsHit, String listName) {
|
||||
|
@ -241,18 +241,17 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
|
||||
//construct a Solr query using aggregated terms to get highlighting
|
||||
//the query is executed later on demand
|
||||
StringBuilder highlightQuery = new StringBuilder();
|
||||
Collection<Term> terms = tcq.getTerms();
|
||||
|
||||
if (terms.size() == 1) {
|
||||
if (tcqRes.keySet().size() == 1) {
|
||||
//simple case, no need to process subqueries and do special escaping
|
||||
Term term = terms.iterator().next();
|
||||
highlightQuery.append(term.getTerm());
|
||||
String term = tcqRes.keySet().iterator().next();
|
||||
highlightQuery.append(term);
|
||||
} else {
|
||||
final int lastTerm = terms.size() - 1;
|
||||
final int lastTerm = tcqRes.keySet().size() - 1;
|
||||
int curTerm = 0;
|
||||
for (Term term : terms) {
|
||||
for (String term : tcqRes.keySet()) {
|
||||
//escape subqueries, they shouldn't be escaped again later
|
||||
final String termS = KeywordSearchUtil.escapeLuceneQuery(term.getTerm(), true, false);
|
||||
final String termS = KeywordSearchUtil.escapeLuceneQuery(term, true, false);
|
||||
if (!termS.contains("*")) {
|
||||
highlightQuery.append(termS);
|
||||
if (lastTerm != curTerm) {
|
||||
@ -292,7 +291,7 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
|
||||
toPopulate.add(new KeyValueQueryContent(f.getName(), resMap, ++resID, f, highlightQueryEscaped, tcq));
|
||||
}
|
||||
//write to bb
|
||||
new ResultWriter(fsContents, tcq, theListName).execute();
|
||||
new ResultWriter(tcqRes, tcq, theListName).execute();
|
||||
|
||||
|
||||
return true;
|
||||
@ -378,7 +377,7 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
|
||||
|
||||
}
|
||||
//write to bb
|
||||
new ResultWriter(uniqueMatches, origQuery, "").execute();
|
||||
new ResultWriter(matchesRes, origQuery, "").execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -428,15 +427,14 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
|
||||
static class ResultWriter extends SwingWorker {
|
||||
|
||||
private static List<ResultWriter> writers = new ArrayList<ResultWriter>();
|
||||
|
||||
private ProgressHandle progress;
|
||||
private KeywordSearchQuery query;
|
||||
private String listName;
|
||||
private Set<FsContent> fsContents;
|
||||
private Map<String, List<FsContent>> hits;
|
||||
final Collection<BlackboardArtifact> na = new ArrayList<BlackboardArtifact>();
|
||||
|
||||
ResultWriter(Set<FsContent> fsContents, KeywordSearchQuery query, String listName) {
|
||||
this.fsContents = fsContents;
|
||||
ResultWriter(Map<String, List<FsContent>> hits, KeywordSearchQuery query, String listName) {
|
||||
this.hits = hits;
|
||||
this.query = query;
|
||||
this.listName = listName;
|
||||
}
|
||||
@ -465,17 +463,19 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
|
||||
}
|
||||
});
|
||||
|
||||
progress.start(fsContents.size());
|
||||
progress.start(hits.keySet().size());
|
||||
int processedFiles = 0;
|
||||
for (final FsContent f : fsContents) {
|
||||
for (final String hit : hits.keySet()) {
|
||||
progress.progress(hit, ++processedFiles);
|
||||
if (this.isCancelled()) {
|
||||
break;
|
||||
}
|
||||
Collection<KeywordWriteResult> written = query.writeToBlackBoard(f, listName);
|
||||
for (KeywordWriteResult w : written) {
|
||||
na.add(w.getArtifact());
|
||||
for (FsContent f : hits.get(hit)) {
|
||||
KeywordWriteResult written = query.writeToBlackBoard(hit, f, listName);
|
||||
if (written != null)
|
||||
na.add(written.getArtifact());
|
||||
}
|
||||
progress.progress(f.getName(), ++processedFiles);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -497,6 +497,5 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueQuery> {
|
||||
writers.remove(w);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +163,7 @@ public class LuceneQuery implements KeywordSearchQuery {
|
||||
return query != null && !query.equals("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
|
||||
private Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
|
||||
List<KeywordWriteResult> ret = new ArrayList<KeywordWriteResult>();
|
||||
KeywordWriteResult written = writeToBlackBoard(query, newFsHit, listName);
|
||||
if (written != null) {
|
||||
|
@ -219,25 +219,6 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<KeywordWriteResult> writeToBlackBoard(FsContent newFsHit, String listName) {
|
||||
Collection<KeywordWriteResult> writeResults = new ArrayList<KeywordWriteResult>();
|
||||
|
||||
//get unique term matches, all cases
|
||||
Set<String> matches = new HashSet<String>();
|
||||
for (Term term : terms) {
|
||||
//caseInsMatches.put(term.getTerm().toLowerCase(), null);
|
||||
matches.add(term.getTerm());
|
||||
}
|
||||
|
||||
for (String regexMatch : matches) {
|
||||
KeywordWriteResult written = writeToBlackBoard(regexMatch, newFsHit, listName);
|
||||
if (written != null)
|
||||
writeResults.add(written);
|
||||
} //for each term
|
||||
|
||||
return writeResults;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, List<FsContent>> performQuery() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user