19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.LinkedHashMap;
24 import java.util.List;
26 import java.util.logging.Level;
27 import org.openide.util.NbBundle;
29 import org.openide.nodes.AbstractNode;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Node;
39 class KeywordSearchQueryDelegator {
41 private List<KeywordList> keywordLists;
42 private List<KeywordSearchQuery> queryDelegates;
43 private static int resultWindowCount = 0;
44 private static Logger logger = Logger.getLogger(KeywordSearchQueryDelegator.class.getName());
46 public KeywordSearchQueryDelegator(List<KeywordList> keywordLists) {
47 this.keywordLists = keywordLists;
53 queryDelegates =
new ArrayList<>();
55 for (KeywordList keywordList : keywordLists) {
56 for (Keyword keyword : keywordList.getKeywords()) {
57 KeywordSearchQuery query;
58 if (keyword.isLiteral()) {
60 if (keyword.isWholeword()) {
61 query =
new LuceneQuery(keywordList, keyword);
65 query =
new TermComponentQuery(keywordList, keyword);
67 query.setSubstringQuery();
71 query =
new TermComponentQuery(keywordList, keyword);
73 queryDelegates.add(query);
82 public void execute() {
83 Collection<QueryRequest> queryRequests =
new ArrayList<>();
85 StringBuilder queryConcat =
new StringBuilder();
86 for (KeywordSearchQuery q : queryDelegates) {
87 Map<String, Object> kvs =
new LinkedHashMap<>();
88 final String queryStr = q.getQueryString();
89 queryConcat.append(queryStr).append(
" ");
90 queryRequests.add(
new QueryRequest(kvs, ++queryID, q));
93 String queryConcatStr = queryConcat.toString();
94 final int queryConcatStrLen = queryConcatStr.length();
95 final String queryStrShort = queryConcatStrLen > 15 ? queryConcatStr.substring(0, 14) +
"..." : queryConcatStr;
96 final String windowTitle = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.execute.exeWinTitle", ++resultWindowCount, queryStrShort);
97 DataResultTopComponent searchResultWin = DataResultTopComponent.createInstance(windowTitle);
100 if (queryRequests.size() > 0) {
102 = Children.create(
new KeywordSearchResultFactory(queryRequests, searchResultWin),
true);
104 rootNode =
new AbstractNode(childNodes);
106 rootNode = Node.EMPTY;
109 final String pathText = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.pathText.text");
111 DataResultTopComponent.initInstance(pathText, rootNode, queryRequests.size(), searchResultWin);
113 searchResultWin.requestActive();
121 public boolean validate() {
122 boolean allValid =
true;
123 for (KeywordSearchQuery tcq : queryDelegates) {
124 if (!tcq.validate()) {
125 logger.log(Level.WARNING,
"Query has invalid syntax: {0}", tcq.getQueryString());