mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
TSK-318 Hide special chars escaping from user in List search
- additionally, allow for user to add and search 2 identical keywords from the list, where one is regex and another is literal (escaped) - add Regex column to result view that makes the like queries distinct
This commit is contained in:
parent
91bdf52fe1
commit
e061b4ec3b
@ -23,7 +23,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import org.openide.util.lookup.ServiceProvider;
|
||||
import org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer;
|
||||
import org.sleuthkit.autopsy.keywordsearch.KeywordSearch.QueryType;
|
||||
@ -74,7 +74,7 @@ public class KeywordSearchDataExplorer implements DataExplorer {
|
||||
private void search() {
|
||||
KeywordSearchQueryManager man = null;
|
||||
if (tc.isMultiwordQuery()) {
|
||||
final Map<String, Boolean> keywords = tc.getQueryList();
|
||||
final List<Keyword> keywords = tc.getQueryList();
|
||||
if (keywords.isEmpty()) {
|
||||
KeywordSearchUtil.displayDialog("Keyword Search Error", "Keyword list is empty, please add at least one keyword to the list", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
|
||||
return;
|
||||
|
@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.keywordsearch;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
@ -264,7 +264,7 @@ public final class KeywordSearchHistoryTopComponent extends TopComponent impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getQueryList() {
|
||||
public List<Keyword> getQueryList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -416,7 +416,7 @@ public final class KeywordSearchListImportExportTopComponent extends TopComponen
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getQueryList() {
|
||||
public List<Keyword> getQueryList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -167,19 +167,19 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
//some hardcoded keywords for testing
|
||||
|
||||
//phone number
|
||||
tableModel.addKeyword("\\d\\d\\d[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false);
|
||||
tableModel.addKeyword("\\d{8,10}", false);
|
||||
tableModel.addKeyword("phone|fax", false);
|
||||
tableModel.addKeyword(new Keyword("\\d\\d\\d[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false));
|
||||
tableModel.addKeyword(new Keyword("\\d{8,10}", false));
|
||||
tableModel.addKeyword(new Keyword("phone|fax", false));
|
||||
//IP address
|
||||
tableModel.addKeyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false);
|
||||
tableModel.addKeyword(new Keyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false));
|
||||
//email
|
||||
tableModel.addKeyword("[e\\-]{0,2}mail", false);
|
||||
tableModel.addKeyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false);
|
||||
tableModel.addKeyword(new Keyword("[e\\-]{0,2}mail", false));
|
||||
tableModel.addKeyword(new Keyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false));
|
||||
//URL
|
||||
tableModel.addKeyword("ftp|sftp|ssh|http|https|www", false);
|
||||
tableModel.addKeyword(new Keyword("ftp|sftp|ssh|http|https|www", false));
|
||||
//escaped literal word \d\d\d
|
||||
tableModel.addKeyword("\\Q\\d\\d\\d\\E", false);
|
||||
tableModel.addKeyword("\\d\\d\\d\\d", true);
|
||||
tableModel.addKeyword(new Keyword("\\Q\\d\\d\\d\\E", false));
|
||||
tableModel.addKeyword(new Keyword("\\d\\d\\d\\d", true));
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
@ -399,10 +399,11 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
|
||||
String newWord = addWordField.getText().trim();
|
||||
boolean isLiteral = !chRegex.isSelected();
|
||||
final Keyword keyword = new Keyword(newWord, isLiteral);
|
||||
|
||||
if (newWord.equals("")) {
|
||||
return;
|
||||
} else if (keywordExists(newWord, isLiteral)) {
|
||||
} else if (keywordExists(keyword)) {
|
||||
KeywordSearchUtil.displayDialog("New Keyword Entry", "Keyword already exists in the list.", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
|
||||
return;
|
||||
}
|
||||
@ -423,7 +424,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
}
|
||||
|
||||
//add & reset checkbox
|
||||
tableModel.addKeyword(newWord, isLiteral);
|
||||
tableModel.addKeyword(keyword);
|
||||
chRegex.setSelected(false);
|
||||
addWordField.setText("");
|
||||
|
||||
@ -445,7 +446,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
final String FEATURE_NAME = "Save Keyword List";
|
||||
KeywordSearchListsXML writer = KeywordSearchListsXML.getCurrent();
|
||||
|
||||
Map<String,Boolean> keywords = tableModel.getAllKeywords();
|
||||
List<Keyword> keywords = tableModel.getAllKeywords();
|
||||
if (keywords.isEmpty()) {
|
||||
KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword List is empty and cannot be saved", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
|
||||
return;
|
||||
@ -714,7 +715,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getQueryList() {
|
||||
public List<Keyword> getQueryList() {
|
||||
return getAllKeywords();
|
||||
}
|
||||
|
||||
@ -738,16 +739,16 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String,Boolean> getAllKeywords() {
|
||||
List<Keyword> getAllKeywords() {
|
||||
return tableModel.getAllKeywords();
|
||||
}
|
||||
|
||||
public Map<String,Boolean> getSelectedKeywords() {
|
||||
List<Keyword> getSelectedKeywords() {
|
||||
return tableModel.getSelectedKeywords();
|
||||
}
|
||||
|
||||
private boolean keywordExists(String keyword, boolean isLiteral) {
|
||||
return tableModel.keywordExists(keyword, isLiteral);
|
||||
private boolean keywordExists(Keyword keyword) {
|
||||
return tableModel.keywordExists(keyword);
|
||||
}
|
||||
|
||||
private class KeywordTableModel extends AbstractTableModel {
|
||||
@ -842,41 +843,40 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
return getValueAt(0, c).getClass();
|
||||
}
|
||||
|
||||
Map<String,Boolean> getAllKeywords() {
|
||||
Map<String,Boolean> ret = new LinkedHashMap<String,Boolean>();
|
||||
List<Keyword> getAllKeywords() {
|
||||
List<Keyword> ret = new ArrayList<Keyword>();
|
||||
for (TableEntry e : keywordData) {
|
||||
ret.put(e.keyword, e.isLiteral);
|
||||
ret.add(new Keyword(e.keyword, e.isLiteral));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Map<String,Boolean> getSelectedKeywords() {
|
||||
Map<String,Boolean> ret = new LinkedHashMap<String,Boolean>();
|
||||
List<Keyword> getSelectedKeywords() {
|
||||
List<Keyword> ret = new ArrayList<Keyword>();
|
||||
for (TableEntry e : keywordData) {
|
||||
if (e.isActive && !e.keyword.equals("")) {
|
||||
ret.put(e.keyword, e.isLiteral);
|
||||
ret.add(new Keyword(e.keyword, e.isLiteral));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
boolean keywordExists(String keyword, boolean isLiteral) {
|
||||
Map<String,Boolean> all = getAllKeywords();
|
||||
return all.containsKey(keyword) && all.get(keyword) == isLiteral;
|
||||
boolean keywordExists(Keyword keyword) {
|
||||
List<Keyword> all = getAllKeywords();
|
||||
return all.contains(keyword);
|
||||
}
|
||||
|
||||
void addKeyword(String keyword, boolean isLiteral) {
|
||||
if (!keywordExists(keyword, isLiteral)) {
|
||||
keywordData.add(new TableEntry(keyword, isLiteral));
|
||||
void addKeyword(Keyword keyword) {
|
||||
if (!keywordExists(keyword)) {
|
||||
keywordData.add(new TableEntry(keyword));
|
||||
}
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
void addKeywords(Map<String,Boolean> keywords) {
|
||||
for (String keyword : keywords.keySet()) {
|
||||
boolean isLiteral = keywords.get(keyword);
|
||||
if (!keywordExists(keyword, isLiteral)) {
|
||||
keywordData.add(new TableEntry(keyword, isLiteral));
|
||||
void addKeywords(List<Keyword> keywords) {
|
||||
for (Keyword keyword : keywords) {
|
||||
if (!keywordExists(keyword)) {
|
||||
keywordData.add(new TableEntry(keyword));
|
||||
}
|
||||
}
|
||||
fireTableDataChanged();
|
||||
@ -885,7 +885,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
void resync(String listName) {
|
||||
KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent();
|
||||
KeywordSearchList list = loader.getList(listName);
|
||||
Map<String,Boolean> keywords = list.getKeywords();
|
||||
List<Keyword> keywords = list.getKeywords();
|
||||
|
||||
deleteAll();
|
||||
addKeywords(keywords);
|
||||
@ -917,12 +917,18 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
|
||||
Boolean isLiteral;
|
||||
Boolean isActive;
|
||||
|
||||
TableEntry(String keyword, Boolean isLiteral, Boolean isActive) {
|
||||
this.keyword = keyword;
|
||||
this.isLiteral = isLiteral;
|
||||
TableEntry(Keyword keyword, Boolean isActive) {
|
||||
this.keyword = keyword.getQuery();
|
||||
this.isLiteral = keyword.isLiteral();
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
TableEntry(Keyword keyword) {
|
||||
this.keyword = keyword.getQuery();
|
||||
this.isLiteral = keyword.isLiteral();
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
TableEntry(String keyword, Boolean isLiteral) {
|
||||
this.keyword = keyword;
|
||||
this.isLiteral = isLiteral;
|
||||
|
@ -183,7 +183,7 @@ public class KeywordSearchListsXML {
|
||||
* @param newList list of keywords
|
||||
* @return true if old list was replaced
|
||||
*/
|
||||
boolean addList(String name, Map<String,Boolean> newList) {
|
||||
boolean addList(String name, List<Keyword> newList) {
|
||||
boolean replaced = false;
|
||||
KeywordSearchList curList = getList(name);
|
||||
final Date now = new Date();
|
||||
@ -265,18 +265,18 @@ public class KeywordSearchListsXML {
|
||||
KeywordSearchList list = theLists.get(listName);
|
||||
String created = dateFormatter.format(list.getDateCreated());
|
||||
String modified = dateFormatter.format(list.getDateModified());
|
||||
Map<String,Boolean> keywords = list.getKeywords();
|
||||
List<Keyword> keywords = list.getKeywords();
|
||||
|
||||
Element listEl = doc.createElement(LIST_EL);
|
||||
listEl.setAttribute(LIST_NAME_ATTR, listName);
|
||||
listEl.setAttribute(LIST_CREATE_ATTR, created);
|
||||
listEl.setAttribute(LIST_MOD_ATTR, modified);
|
||||
|
||||
for (String keyword : keywords.keySet()) {
|
||||
for (Keyword keyword : keywords) {
|
||||
Element keywordEl = doc.createElement(KEYWORD_EL);
|
||||
String regex = keywords.get(keyword)==true?"true":"false";
|
||||
String regex = keyword.isLiteral()==false?"true":"false";
|
||||
keywordEl.setAttribute(KEYWORD_LITERAL_ATTR, regex);
|
||||
keywordEl.setTextContent(keyword);
|
||||
keywordEl.setTextContent(keyword.getQuery());
|
||||
listEl.appendChild(keywordEl);
|
||||
}
|
||||
rootEl.appendChild(listEl);
|
||||
@ -313,7 +313,7 @@ public class KeywordSearchListsXML {
|
||||
final String modified = listEl.getAttribute(LIST_MOD_ATTR);
|
||||
Date createdDate = dateFormatter.parse(created);
|
||||
Date modDate = dateFormatter.parse(modified);
|
||||
Map<String,Boolean> words = new LinkedHashMap<String,Boolean>();
|
||||
List<Keyword> words = new ArrayList<Keyword>();
|
||||
KeywordSearchList list = new KeywordSearchList(name, createdDate, modDate, words);
|
||||
|
||||
//parse all words
|
||||
@ -323,7 +323,7 @@ public class KeywordSearchListsXML {
|
||||
Element wordEl = (Element) wordsNList.item(j);
|
||||
String regex = wordEl.getAttribute(KEYWORD_LITERAL_ATTR);
|
||||
boolean isRegex = regex.equals("true");
|
||||
words.put(wordEl.getTextContent(), isRegex);
|
||||
words.add(new Keyword(wordEl.getTextContent(), isRegex));
|
||||
|
||||
}
|
||||
theLists.put(name, list);
|
||||
@ -410,9 +410,9 @@ class KeywordSearchList {
|
||||
private String name;
|
||||
private Date created;
|
||||
private Date modified;
|
||||
private Map<String,Boolean> keywords;
|
||||
private List<Keyword> keywords;
|
||||
|
||||
KeywordSearchList(String name, Date created, Date modified, Map<String,Boolean> keywords) {
|
||||
KeywordSearchList(String name, Date created, Date modified, List<Keyword> keywords) {
|
||||
this.name = name;
|
||||
this.created = created;
|
||||
this.modified = modified;
|
||||
@ -452,7 +452,7 @@ class KeywordSearchList {
|
||||
return modified;
|
||||
}
|
||||
|
||||
Map<String,Boolean> getKeywords() {
|
||||
List<Keyword> getKeywords() {
|
||||
return keywords;
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,12 @@ public interface KeywordSearchQuery {
|
||||
*/
|
||||
public void escape();
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if query was escaped
|
||||
*/
|
||||
public boolean isEscaped();
|
||||
|
||||
/**
|
||||
* return original query string
|
||||
* @return the query String supplied originally
|
||||
|
@ -45,14 +45,14 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
|
||||
COLLAPSE, DETAIL
|
||||
};
|
||||
//map query->boolean (true if literal, false otherwise)
|
||||
private Map<String, Boolean> queries;
|
||||
|
||||
private List<Keyword> queries;
|
||||
private Presentation presentation;
|
||||
private List<KeywordSearchQuery> queryDelegates;
|
||||
private QueryType queryType;
|
||||
private static Logger logger = Logger.getLogger(KeywordSearchQueryManager.class.getName());
|
||||
|
||||
public KeywordSearchQueryManager(Map<String, Boolean> queries, Presentation presentation) {
|
||||
public KeywordSearchQueryManager(List<Keyword> queries, Presentation presentation) {
|
||||
this.queries = queries;
|
||||
this.presentation = presentation;
|
||||
queryType = QueryType.REGEX;
|
||||
@ -60,16 +60,16 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
}
|
||||
|
||||
public KeywordSearchQueryManager(String query, QueryType qt, Presentation presentation) {
|
||||
queries = new LinkedHashMap<String, Boolean>();
|
||||
queries.put(query, false);
|
||||
queries = new ArrayList<Keyword>();
|
||||
queries.add(new Keyword(query, false));
|
||||
this.presentation = presentation;
|
||||
queryType = qt;
|
||||
init();
|
||||
}
|
||||
|
||||
public KeywordSearchQueryManager(String query, boolean isLiteral, Presentation presentation) {
|
||||
queries = new LinkedHashMap<String, Boolean>();
|
||||
queries.put(query, isLiteral);
|
||||
queries = new ArrayList<Keyword>();
|
||||
queries.add(new Keyword(query, isLiteral));
|
||||
this.presentation = presentation;
|
||||
queryType = QueryType.REGEX;
|
||||
init();
|
||||
@ -77,22 +77,24 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
|
||||
private void init() {
|
||||
queryDelegates = new ArrayList<KeywordSearchQuery>();
|
||||
for (String query : queries.keySet()) {
|
||||
for (Keyword query : queries) {
|
||||
KeywordSearchQuery del = null;
|
||||
switch (queryType) {
|
||||
case WORD:
|
||||
del = new LuceneQuery(query);
|
||||
del = new LuceneQuery(query.getQuery());
|
||||
break;
|
||||
case REGEX:
|
||||
del = new TermComponentQuery(query);
|
||||
del = new TermComponentQuery(query.getQuery());
|
||||
break;
|
||||
default:
|
||||
;
|
||||
}
|
||||
if (query.isLiteral())
|
||||
del.escape();
|
||||
queryDelegates.add(del);
|
||||
|
||||
}
|
||||
escape();
|
||||
//escape();
|
||||
|
||||
}
|
||||
|
||||
@ -115,16 +117,17 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
}
|
||||
|
||||
Node rootNode = null;
|
||||
|
||||
if (things.size() > 0) {
|
||||
Children childThingNodes =
|
||||
Children.create(new KeywordSearchResultFactory(queries.keySet(), things, Presentation.COLLAPSE), true);
|
||||
Children.create(new KeywordSearchResultFactory(queries, things, Presentation.COLLAPSE), true);
|
||||
|
||||
rootNode = new AbstractNode(childThingNodes);
|
||||
} else {
|
||||
rootNode = Node.EMPTY;
|
||||
}
|
||||
|
||||
final String pathText = "Keyword query";
|
||||
final String pathText = "Keyword search";
|
||||
TopComponent searchResultWin = DataResultTopComponent.createInstance("Keyword search", pathText, rootNode, things.size());
|
||||
searchResultWin.requestActive();
|
||||
}
|
||||
@ -132,13 +135,7 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
for (KeywordSearchQuery q : queryDelegates) {
|
||||
boolean shouldEscape = queries.get(q.getQueryString());
|
||||
if (shouldEscape) {
|
||||
q.escape();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -169,6 +166,11 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEscaped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryString() {
|
||||
@ -186,7 +188,7 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* custom KeyValueThing that also stores query object to execute
|
||||
*/
|
||||
class KeyValueThingQuery extends KeyValueThing {
|
||||
@ -202,3 +204,47 @@ class KeyValueThingQuery extends KeyValueThing {
|
||||
this.query = query;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* representation of Keyword input from user
|
||||
*/
|
||||
class Keyword {
|
||||
|
||||
private String query;
|
||||
private boolean isLiteral;
|
||||
|
||||
Keyword(String query, boolean isLiteral) {
|
||||
this.query = query;
|
||||
this.isLiteral = isLiteral;
|
||||
}
|
||||
String getQuery() {return query;}
|
||||
boolean isLiteral() {return isLiteral;}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Keyword other = (Keyword) obj;
|
||||
if ((this.query == null) ? (other.query != null) : !this.query.equals(other.query)) {
|
||||
return false;
|
||||
}
|
||||
if (this.isLiteral != other.isLiteral) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 17 * hash + (this.query != null ? this.query.hashCode() : 0);
|
||||
hash = 17 * hash + (this.isLiteral ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,17 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
|
||||
//these are merged with FsContentPropertyType defined properties
|
||||
public static enum CommonPropertyTypes {
|
||||
|
||||
QUERY {
|
||||
KEYWORD {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Query";
|
||||
return "Keyword";
|
||||
}
|
||||
},
|
||||
REGEX {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Regex";
|
||||
}
|
||||
},
|
||||
MATCH {
|
||||
@ -73,19 +79,19 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
|
||||
}
|
||||
},}
|
||||
private Presentation presentation;
|
||||
private Collection<String> queries;
|
||||
private List<Keyword> queries;
|
||||
private Collection<KeyValueThing> things;
|
||||
private static final Logger logger = Logger.getLogger(KeywordSearchResultFactory.class.getName());
|
||||
|
||||
KeywordSearchResultFactory(Collection<String> queries, Collection<KeyValueThing> things, Presentation presentation) {
|
||||
KeywordSearchResultFactory(List<Keyword> queries, Collection<KeyValueThing> things, Presentation presentation) {
|
||||
this.queries = queries;
|
||||
this.things = things;
|
||||
this.presentation = presentation;
|
||||
}
|
||||
|
||||
KeywordSearchResultFactory(String query, Collection<KeyValueThing> things, Presentation presentation) {
|
||||
queries = new ArrayList<String>();
|
||||
queries.add(query);
|
||||
queries = new ArrayList<Keyword>();
|
||||
queries.add(new Keyword(query, false));
|
||||
this.presentation = presentation;
|
||||
this.things = things;
|
||||
}
|
||||
@ -115,15 +121,21 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
|
||||
final String typeStr = type.toString();
|
||||
toSet.put(typeStr, value);
|
||||
}
|
||||
public static void setCommonProperty(Map<String, Object> toSet, CommonPropertyTypes type, Boolean value) {
|
||||
final String typeStr = type.toString();
|
||||
toSet.put(typeStr, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean createKeys(List<KeyValueThing> toPopulate) {
|
||||
int id = 0;
|
||||
if (presentation == Presentation.DETAIL) {
|
||||
for (String query : queries) {
|
||||
for (Keyword keyword : queries) {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
final String query = keyword.getQuery();
|
||||
initCommonProperties(map);
|
||||
setCommonProperty(map, CommonPropertyTypes.QUERY, query);
|
||||
setCommonProperty(map, CommonPropertyTypes.KEYWORD, query);
|
||||
setCommonProperty(map, CommonPropertyTypes.REGEX, Boolean.valueOf(!keyword.isLiteral()));
|
||||
toPopulate.add(new KeyValueThing(query, map, ++id));
|
||||
}
|
||||
} else {
|
||||
@ -132,7 +144,9 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
|
||||
Map<String, Object> map = thing.getMap();
|
||||
initCommonProperties(map);
|
||||
final String query = thing.getName();
|
||||
setCommonProperty(map, CommonPropertyTypes.QUERY, query);
|
||||
setCommonProperty(map, CommonPropertyTypes.KEYWORD, query);
|
||||
KeyValueThingQuery thingQuery = (KeyValueThingQuery) thing;
|
||||
setCommonProperty(map, CommonPropertyTypes.REGEX, Boolean.valueOf(!thingQuery.getQuery().isEscaped()));
|
||||
//toPopulate.add(new KeyValueThing(query, map, ++id));
|
||||
toPopulate.add(thing);
|
||||
}
|
||||
|
@ -19,8 +19,7 @@
|
||||
package org.sleuthkit.autopsy.keywordsearch;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.openide.windows.TopComponent;
|
||||
|
||||
@ -194,7 +193,7 @@ public class KeywordSearchSimpleTopComponent extends TopComponent implements Key
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getQueryList() {
|
||||
public List<Keyword> getQueryList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,10 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.keywordsearch;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
@ -146,7 +145,7 @@ public final class KeywordSearchTabsTopComponent extends TopComponent implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Boolean> getQueryList() {
|
||||
public List<Keyword> getQueryList() {
|
||||
KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent();
|
||||
if (selected == null) {
|
||||
return null;
|
||||
|
@ -19,20 +19,20 @@
|
||||
package org.sleuthkit.autopsy.keywordsearch;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* common methods for the KeywordSearch TCs / tabs
|
||||
*
|
||||
*/
|
||||
public interface KeywordSearchTopComponentInterface {
|
||||
interface KeywordSearchTopComponentInterface {
|
||||
|
||||
boolean isMultiwordQuery();
|
||||
boolean isLuceneQuerySelected();
|
||||
boolean isRegexQuerySelected();
|
||||
String getQueryText();
|
||||
Map<String, Boolean> getQueryList();
|
||||
List<Keyword> getQueryList();
|
||||
void setFilesIndexed(int filesIndexed);
|
||||
void addSearchButtonListener(ActionListener l);
|
||||
|
||||
|
@ -59,6 +59,11 @@ public class LuceneQuery implements KeywordSearchQuery {
|
||||
queryEscaped = KeywordSearchUtil.escapeLuceneQuery(query, true, false);
|
||||
isEscaped = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEscaped() {
|
||||
return isEscaped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEscapedQueryString() {
|
||||
|
@ -49,7 +49,7 @@ import org.sleuthkit.autopsy.keywordsearch.KeywordSearchQueryManager.Presentatio
|
||||
import org.sleuthkit.datamodel.FsContent;
|
||||
|
||||
public class TermComponentQuery implements KeywordSearchQuery {
|
||||
|
||||
|
||||
private static final int TERMS_UNLIMITED = -1;
|
||||
//corresponds to field in Solr schema, analyzed with white-space tokenizer only
|
||||
private static final String TERMS_SEARCH_FIELD = "content_ws";
|
||||
@ -60,30 +60,26 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
private String queryEscaped;
|
||||
private boolean isEscaped;
|
||||
private List<Term> terms;
|
||||
|
||||
|
||||
public TermComponentQuery(String query) {
|
||||
this.termsQuery = query;
|
||||
this.queryEscaped = query;
|
||||
isEscaped = false;
|
||||
terms = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
//treat as literal
|
||||
//TODO for actual literal query to work in Java/Solr
|
||||
//might need to either: use terms prefix (not regex) query with the literal
|
||||
//or append .* to the literal regex
|
||||
queryEscaped = Pattern.quote(termsQuery);
|
||||
isEscaped = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean validate() {
|
||||
if (queryEscaped.equals("")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
boolean valid = true;
|
||||
try {
|
||||
Pattern.compile(queryEscaped);
|
||||
@ -95,6 +91,11 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEscaped() {
|
||||
return isEscaped;
|
||||
}
|
||||
|
||||
/*
|
||||
* helper method to create a Solr terms component query
|
||||
*/
|
||||
@ -110,9 +111,9 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
q.setTermsRegex(queryEscaped);
|
||||
q.addTermsField(TERMS_SEARCH_FIELD);
|
||||
q.setTimeAllowed(TERMS_TIMEOUT);
|
||||
|
||||
|
||||
return q;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -120,7 +121,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
*/
|
||||
protected List<Term> executeQuery(SolrQuery q) {
|
||||
Server.Core solrCore = KeywordSearch.getServer().getCore();
|
||||
|
||||
|
||||
List<Term> termsCol = null;
|
||||
try {
|
||||
TermsResponse tr = solrCore.queryTerms(q);
|
||||
@ -131,17 +132,17 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
return null; //no need to create result view, just display error dialog
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getEscapedQueryString() {
|
||||
return this.queryEscaped;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getQueryString() {
|
||||
return this.termsQuery;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<Term> getTerms() {
|
||||
return terms;
|
||||
@ -154,7 +155,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
@Override
|
||||
public List<FsContent> performQuery() {
|
||||
List<FsContent> results = new ArrayList<FsContent>();
|
||||
|
||||
|
||||
final SolrQuery q = createQuery();
|
||||
terms = executeQuery(q);
|
||||
|
||||
@ -179,7 +180,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
++curTerm;
|
||||
}
|
||||
List<FsContent> uniqueMatches = new ArrayList<FsContent>();
|
||||
|
||||
|
||||
if (!terms.isEmpty()) {
|
||||
LuceneQuery filesQuery = new LuceneQuery(filesQueryB.toString());
|
||||
//filesQuery.escape();
|
||||
@ -206,18 +207,18 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
} else {
|
||||
results.addAll(uniqueMatches);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
SolrQuery q = createQuery();
|
||||
|
||||
|
||||
logger.log(Level.INFO, "Executing TermsComponent query: " + q.toString());
|
||||
|
||||
|
||||
final SwingWorker worker = new TermsQueryWorker(q);
|
||||
worker.execute();
|
||||
}
|
||||
@ -227,9 +228,9 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
* @param terms
|
||||
*/
|
||||
private void publishNodes(List<Term> terms) {
|
||||
|
||||
|
||||
Collection<KeyValueThing> things = new ArrayList<KeyValueThing>();
|
||||
|
||||
|
||||
Iterator<Term> it = terms.iterator();
|
||||
int termID = 0;
|
||||
//long totalMatches = 0;
|
||||
@ -243,17 +244,17 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
things.add(new KeyValueThing(match, kvs, ++termID));
|
||||
//totalMatches += matches;
|
||||
}
|
||||
|
||||
|
||||
Node rootNode = null;
|
||||
if (things.size() > 0) {
|
||||
Children childThingNodes =
|
||||
Children.create(new KeywordSearchResultFactory(termsQuery, things, Presentation.DETAIL), true);
|
||||
|
||||
|
||||
rootNode = new AbstractNode(childThingNodes);
|
||||
} else {
|
||||
rootNode = Node.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
final String pathText = "Term query";
|
||||
// String pathText = "RegEx query: " + termsQuery
|
||||
//+ " Files with exact matches: " + Long.toString(totalMatches) + " (also listing approximate matches)";
|
||||
@ -262,29 +263,29 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
searchResultWin.requestActive(); // make it the active top component
|
||||
|
||||
}
|
||||
|
||||
|
||||
class TermsQueryWorker extends SwingWorker<List<Term>, Void> {
|
||||
|
||||
|
||||
private SolrQuery q;
|
||||
private ProgressHandle progress;
|
||||
|
||||
|
||||
TermsQueryWorker(SolrQuery q) {
|
||||
this.q = q;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<Term> doInBackground() throws Exception {
|
||||
progress = ProgressHandleFactory.createHandle("Terms query task");
|
||||
progress.start();
|
||||
progress.progress("Running Terms query.");
|
||||
|
||||
|
||||
terms = executeQuery(q);
|
||||
|
||||
|
||||
progress.progress("Terms query completed.");
|
||||
|
||||
|
||||
return terms;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
if (!this.isCancelled()) {
|
||||
@ -293,7 +294,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
|
||||
publishNodes(terms);
|
||||
} catch (InterruptedException e) {
|
||||
logger.log(Level.INFO, "Exception while executing regex query,", e);
|
||||
|
||||
|
||||
} catch (ExecutionException e) {
|
||||
logger.log(Level.INFO, "Exception while executing regex query,", e);
|
||||
} finally {
|
||||
|
Loading…
x
Reference in New Issue
Block a user