20 package org.sleuthkit.autopsy.keywordsearch;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.LinkedHashMap;
25 import java.util.List;
27 import java.util.logging.Level;
28 import org.openide.util.NbBundle;
30 import org.openide.nodes.AbstractNode;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Node;
40 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());
47 public KeywordSearchQueryDelegator(List<KeywordList> keywordLists) {
48 this.keywordLists = keywordLists;
54 queryDelegates =
new ArrayList<>();
56 for (KeywordList keywordList : keywordLists) {
57 for (Keyword keyword : keywordList.getKeywords()) {
58 KeywordSearchQuery query;
59 if (keyword.isLiteral()) {
61 if (keyword.isWholeword()) {
62 query =
new LuceneQuery(keywordList, keyword);
67 query =
new TermComponentQuery(keywordList, keyword);
69 query.setSubstringQuery();
74 query =
new TermComponentQuery(keywordList, keyword);
76 queryDelegates.add(query);
85 public void execute() {
86 Collection<QueryRequest> queryRequests =
new ArrayList<>();
88 StringBuilder queryConcat =
new StringBuilder();
89 for (KeywordSearchQuery q : queryDelegates) {
90 Map<String, Object> kvs =
new LinkedHashMap<>();
91 final String queryStr = q.getQueryString();
92 queryConcat.append(queryStr).append(
" ");
93 queryRequests.add(
new QueryRequest(kvs, ++queryID, q));
96 String queryConcatStr = queryConcat.toString();
97 final int queryConcatStrLen = queryConcatStr.length();
98 final String queryStrShort = queryConcatStrLen > 15 ? queryConcatStr.substring(0, 14) +
"..." : queryConcatStr;
99 final String windowTitle = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.execute.exeWinTitle", ++resultWindowCount, queryStrShort);
100 DataResultTopComponent searchResultWin = DataResultTopComponent.createInstance(windowTitle);
103 if (queryRequests.size() > 0) {
104 Children childNodes =
105 Children.create(
new KeywordSearchResultFactory(queryRequests, searchResultWin),
true);
107 rootNode =
new AbstractNode(childNodes);
109 rootNode = Node.EMPTY;
112 final String pathText = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.pathText.text");
114 DataResultTopComponent.initInstance(pathText, rootNode, queryRequests.size(), searchResultWin);
116 searchResultWin.requestActive();
123 public boolean validate() {
124 boolean allValid =
true;
125 for (KeywordSearchQuery tcq : queryDelegates) {
126 if (!tcq.validate()) {
127 logger.log(Level.WARNING,
"Query has invalid syntax: {0}", tcq.getQueryString());