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)
70 static SearchResults runFileSearchDebug(String userName,
71 List<AbstractFilter> filters,
80 List<AttributeType> attributesNeededForGroupingOrSorting =
new ArrayList<>();
81 attributesNeededForGroupingOrSorting.add(groupAttributeType);
82 attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes());
85 List<Result> results =
SearchFiltering.runQueries(filters, caseDb, centralRepoDb);
88 addAttributes(attributesNeededForGroupingOrSorting, results, caseDb, centralRepoDb);
91 SearchResults searchResults =
new SearchResults(groupSortingType, groupAttributeType, fileSortingMethod);
92 searchResults.add(results);
95 searchResults.sortGroupsAndFiles();
96 Map<GroupKey, List<Result>> resultHashMap = searchResults.toLinkedHashMap();
97 SearchKey searchKey =
new SearchKey(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod);
99 searchCache.put(searchKey, resultHashMap);
101 return searchResults;
123 List<AbstractFilter> filters,
128 Map<GroupKey, List<Result>> searchResults =
runFileSearch(userName, filters,
129 groupAttributeType, groupSortingType, fileSortingMethod, caseDb, centralRepoDb);
130 LinkedHashMap<GroupKey, Integer> groupSizes =
new LinkedHashMap<>();
131 for (
GroupKey groupKey : searchResults.keySet()) {
132 groupSizes.put(groupKey, searchResults.get(groupKey).size());
160 List<AbstractFilter> filters,
169 List<Result> filesInGroup = null;
170 SearchKey searchKey =
new SearchKey(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod);
171 Map<GroupKey, List<Result>> resultsMap;
173 resultsMap = searchCache.getIfPresent(searchKey);
175 if (resultsMap != null) {
176 filesInGroup = resultsMap.get(groupKey);
178 List<Result> page =
new ArrayList<>();
179 if (filesInGroup == null) {
180 logger.log(Level.INFO,
"Group {0} was not cached, performing search to cache all groups again", groupKey);
181 runFileSearch(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod, caseDb, centralRepoDb);
183 resultsMap = searchCache.getIfPresent(searchKey.getKeyString());
185 if (resultsMap != null) {
186 filesInGroup = resultsMap.get(groupKey);
188 if (filesInGroup == null) {
189 logger.log(Level.WARNING,
"Group {0} did not exist in cache or new search results", groupKey);
194 if (filesInGroup.size() < startingEntry) {
195 logger.log(Level.WARNING,
"Group only contains {0} files, starting entry of {1} is too large.",
new Object[]{filesInGroup.size(), startingEntry});
199 for (
int i = startingEntry; (i < startingEntry + numberOfEntries)
200 && (i < filesInGroup.size()); i++) {
201 page.add(filesInGroup.get(i));
214 @NbBundle.Messages({
"FileSearch.documentSummary.noPreview=No preview available.",
215 "FileSearch.documentSummary.noBytes=No bytes read for document, unable to display preview."})
220 localSummarizer = SummaryHelpers.getLocalSummarizer();
223 if (localSummarizer != null) {
226 summary = localSummarizer.
summarize(file, 40);
227 }
catch (IOException ex) {
228 return new TextSummary(Bundle.FileSearch_documentSummary_noPreview(), null, 0);
231 if (summary == null || StringUtils.isBlank(summary.
getSummaryText())) {
233 summary = SummaryHelpers.getDefaultSummary(file);
256 List<AbstractFilter> filters,
266 List<AttributeType> attributesNeededForGroupingOrSorting =
new ArrayList<>();
267 attributesNeededForGroupingOrSorting.add(groupAttributeType);
268 attributesNeededForGroupingOrSorting.addAll(fileSortingMethod.getRequiredAttributes());
271 List<Result> results =
SearchFiltering.runQueries(filters, caseDb, centralRepoDb);
274 addAttributes(attributesNeededForGroupingOrSorting, results, caseDb, centralRepoDb);
277 SearchResults searchResults =
new SearchResults(groupSortingType, groupAttributeType, fileSortingMethod);
278 searchResults.add(results);
279 Map<GroupKey, List<Result>> resultHashMap = searchResults.toLinkedHashMap();
280 SearchKey searchKey =
new SearchKey(userName, filters, groupAttributeType, groupSortingType, fileSortingMethod);
282 searchCache.put(searchKey, resultHashMap);
285 return resultHashMap;
304 attr.addAttributeToResults(results, caseDb, centralRepoDb);
static void addAttributes(List< AttributeType > attrs, List< Result > results, SleuthkitCase caseDb, CentralRepository centralRepoDb)
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)
static final Logger logger
static Map< GroupKey, Integer > getGroupSizes(String userName, List< AbstractFilter > filters, AttributeType groupAttributeType, Group.GroupSortingAlgorithm groupSortingType, ResultsSorter.SortingMethod fileSortingMethod, SleuthkitCase caseDb, CentralRepository centralRepoDb)
synchronized static Logger getLogger(String name)
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)