From 83f8d575e941653efe94d88a0406cff5927a6c5f Mon Sep 17 00:00:00 2001 From: esaunders Date: Wed, 7 Dec 2016 16:14:00 -0500 Subject: [PATCH 1/2] Add quotes around the keyword when the search results are not available to make highlighting work correctly. --- .../org/sleuthkit/autopsy/keywordsearch/HighlightedText.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java index fe87ac26cc..02b3391b5f 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/HighlightedText.java @@ -84,7 +84,7 @@ class HighlightedText implements IndexedText, TextMarkupLookup { //when the results are not known and need to requery to get hits HighlightedText(long objectId, String solrQuery, boolean isRegex, String originalQuery) { - this(objectId, solrQuery, isRegex); + this(objectId, KeywordSearchUtil.quoteQuery(solrQuery), isRegex); this.originalQuery = originalQuery; } From a782e52f8041a5cc32ca6d9e8c81b10801806100 Mon Sep 17 00:00:00 2001 From: esaunders Date: Wed, 7 Dec 2016 16:17:24 -0500 Subject: [PATCH 2/2] Removed filterOneHitPerDocument() since (a) it's use prevents the display of hits across multiple pages/chunks and (b) QueryResults.writeAllHitsToBlackBoard() takes care of ensuring that only a single blackboard artifact is created per document. --- .../autopsy/keywordsearch/LuceneQuery.java | 36 +------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java index 0b7941747e..5cdf3ad438 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java @@ -206,7 +206,6 @@ class LuceneQuery implements KeywordSearchQuery { QueryResponse response; SolrDocumentList resultList; Map>> highlightResponse; - Set uniqueSolrDocumentsWithHits; response = solrServer.query(q, METHOD.POST); @@ -215,9 +214,6 @@ class LuceneQuery implements KeywordSearchQuery { // objectId_chunk -> "text" -> List of previews highlightResponse = response.getHighlighting(); - // get the unique set of files with hits - uniqueSolrDocumentsWithHits = filterOneHitPerDocument(resultList); - // cycle through results in sets of MAX_RESULTS for (int start = 0; !allMatchesFetched; start = start + MAX_RESULTS) { q.setStart(start); @@ -232,7 +228,7 @@ class LuceneQuery implements KeywordSearchQuery { return matches; } - for (SolrDocument resultDoc : uniqueSolrDocumentsWithHits) { + for (SolrDocument resultDoc : resultList) { KeywordHit contentHit; try { contentHit = createKeywordtHit(resultDoc, highlightResponse, sleuthkitCase); @@ -297,36 +293,6 @@ class LuceneQuery implements KeywordSearchQuery { return q; } - /** - * Create the minimum set of documents. Ignores chunk IDs. Only one hit per - * file in results. - * - * @param resultList - * - * @return - */ - private Set filterOneHitPerDocument(SolrDocumentList resultList) { - // sort the list so that we consistently pick the same chunk each time. - // note this sort is doing a string comparison and not an integer comparison, so - // chunk 10 will be smaller than chunk 9. - Collections.sort(resultList, new Comparator() { - @Override - public int compare(SolrDocument left, SolrDocument right) { - // ID is in the form of ObjectId_Chunk - String leftID = left.getFieldValue(Server.Schema.ID.toString()).toString(); - String rightID = right.getFieldValue(Server.Schema.ID.toString()).toString(); - return leftID.compareTo(rightID); - } - }); - - // NOTE: We could probably just iterate through the list and compare each ID with the - // previous ID to get the unique documents faster than using this set now that the list - // is sorted. - Set solrDocumentsWithMatches = new TreeSet<>(new SolrDocumentComparatorIgnoresChunkId()); - solrDocumentsWithMatches.addAll(resultList); - return solrDocumentsWithMatches; - } - private KeywordHit createKeywordtHit(SolrDocument solrDoc, Map>> highlightResponse, SleuthkitCase caseDb) throws TskException { /** * Get the first snippet from the document if keyword search is