19 package org.sleuthkit.autopsy.discovery.search;
21 import com.google.common.cache.Cache;
22 import com.google.common.cache.CacheBuilder;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.LinkedHashMap;
26 import java.util.List;
28 import java.util.logging.Level;
29 import org.apache.commons.lang.StringUtils;
30 import org.openide.util.NbBundle;
48 private static final Cache<SearchKey, Map<GroupKey, List<Result>>>
searchCache = CacheBuilder.newBuilder()
49 .maximumSize(MAXIMUM_CACHE_SIZE)
74 static SearchResults runFileSearchDebug(String userName,
75 List<AbstractFilter> filters,
84 List<AttributeType> attributesNeededForGroupingOrSorting =
new ArrayList<>();
85 attributesNeededForGroupingOrSorting.add(groupAttributeType);
86 attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes());
89 List<Result> results =
SearchFiltering.runQueries(filters, caseDb, centralRepoDb, context);
92 addAttributes(attributesNeededForGroupingOrSorting, results, caseDb, centralRepoDb, context);
95 SearchResults searchResults =
new SearchResults(groupSortingType, groupAttributeType, fileSortingMethod);
96 searchResults.add(results);
99 searchResults.sortGroupsAndFiles();
100 Map<GroupKey, List<Result>> resultHashMap = searchResults.toLinkedHashMap();
101 SearchKey searchKey =
new SearchKey(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod);
103 searchCache.put(searchKey, resultHashMap);
105 return searchResults;
131 List<AbstractFilter> filters,
136 Map<GroupKey, List<Result>> searchResults =
runFileSearch(userName, filters,
137 groupAttributeType, groupSortingType, fileSortingMethod, caseDb, centralRepoDb, context);
138 LinkedHashMap<GroupKey, Integer> groupSizes =
new LinkedHashMap<>();
139 for (
GroupKey groupKey : searchResults.keySet()) {
140 if (context.searchIsCancelled()) {
143 groupSizes.put(groupKey, searchResults.get(groupKey).size());
175 List<AbstractFilter> filters,
184 List<Result> filesInGroup = null;
185 SearchKey searchKey =
new SearchKey(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod);
186 Map<GroupKey, List<Result>> resultsMap;
188 resultsMap = searchCache.getIfPresent(searchKey);
190 if (resultsMap != null) {
191 filesInGroup = resultsMap.get(groupKey);
193 List<Result> page =
new ArrayList<>();
194 if (filesInGroup == null) {
195 logger.log(Level.INFO,
"Group {0} was not cached, performing search to cache all groups again", groupKey);
196 runFileSearch(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod, caseDb, centralRepoDb, context);
198 resultsMap = searchCache.getIfPresent(searchKey.getKeyString());
200 if (resultsMap != null) {
201 filesInGroup = resultsMap.get(groupKey);
203 if (filesInGroup == null) {
204 logger.log(Level.WARNING,
"Group {0} did not exist in cache or new search results", groupKey);
209 if (filesInGroup.size() < startingEntry) {
210 logger.log(Level.WARNING,
"Group only contains {0} files, starting entry of {1} is too large.",
new Object[]{filesInGroup.size(), startingEntry});
214 for (
int i = startingEntry; (i < startingEntry + numberOfEntries)
215 && (i < filesInGroup.size()); i++) {
216 page.add(filesInGroup.get(i));
229 @NbBundle.Messages({
"FileSearch.documentSummary.noPreview=No preview available.",
230 "FileSearch.documentSummary.noBytes=No bytes read for document, unable to display preview."})
235 localSummarizer = SummaryHelpers.getLocalSummarizer();
237 if (localSummarizer != null) {
240 summary = localSummarizer.
summarize(file, 40);
241 }
catch (IOException ex) {
242 return new TextSummary(Bundle.FileSearch_documentSummary_noPreview(), null, 0);
245 if (summary == null || StringUtils.isBlank(summary.
getSummaryText())) {
247 summary = SummaryHelpers.getDefaultSummary(file);
274 List<AbstractFilter> filters,
284 List<AttributeType> attributesNeededForGroupingOrSorting =
new ArrayList<>();
285 attributesNeededForGroupingOrSorting.add(groupAttributeType);
286 attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes());
289 List<Result> results =
SearchFiltering.runQueries(filters, caseDb, centralRepoDb, context);
292 addAttributes(attributesNeededForGroupingOrSorting, results, caseDb, centralRepoDb, context);
295 SearchResults searchResults =
new SearchResults(groupSortingType, groupAttributeType, fileSortingMethod);
296 searchResults.add(results);
297 Map<GroupKey, List<Result>> resultHashMap = searchResults.toLinkedHashMap();
298 SearchKey searchKey =
new SearchKey(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod);
300 searchCache.put(searchKey, resultHashMap);
303 return resultHashMap;
326 attr.addAttributeToResults(results, caseDb, centralRepoDb, context);
TextSummary summarize(AbstractFile file, int summarySize)
static final int MAXIMUM_CACHE_SIZE
static final Cache< SearchKey, Map< GroupKey, List< Result > > > searchCache
static TextSummary summarize(AbstractFile file)
static Map< GroupKey, List< Result > > runFileSearch(String userName, List< AbstractFilter > filters, AttributeType groupAttributeType, Group.GroupSortingAlgorithm groupSortingType, ResultsSorter.SortingMethod fileSortingMethod, SleuthkitCase caseDb, CentralRepository centralRepoDb, SearchContext context)
static void addAttributes(List< AttributeType > attrs, List< Result > results, SleuthkitCase caseDb, CentralRepository centralRepoDb, SearchContext context)
static final Logger logger
static List< Result > getFilesInGroup(String userName, List< AbstractFilter > filters, AttributeType groupAttributeType, Group.GroupSortingAlgorithm groupSortingType, ResultsSorter.SortingMethod fileSortingMethod, GroupKey groupKey, int startingEntry, int numberOfEntries, SleuthkitCase caseDb, CentralRepository centralRepoDb, SearchContext context)
synchronized static Logger getLogger(String name)
static Map< GroupKey, Integer > getGroupSizes(String userName, List< AbstractFilter > filters, AttributeType groupAttributeType, Group.GroupSortingAlgorithm groupSortingType, ResultsSorter.SortingMethod fileSortingMethod, SleuthkitCase caseDb, CentralRepository centralRepoDb, SearchContext context)