Reduced number of custructors in Keyword class

This commit is contained in:
Eugene Livis 2017-04-10 17:03:11 -04:00
parent 06daab8623
commit aae52e2467
7 changed files with 39 additions and 41 deletions

View File

@ -74,7 +74,7 @@ class EnCaseKeywordSearchList extends KeywordSearchList {
if (child.flags.contains(EncaseFlag.pg)) { // Skip GREP keywords if (child.flags.contains(EncaseFlag.pg)) { // Skip GREP keywords
break; break;
} }
children.add(new Keyword(child.value, true)); children.add(new Keyword(child.value, true, true));
break; break;
} }
} }

View File

@ -179,7 +179,7 @@ class HighlightedText implements IndexedText {
// Run a query to figure out which chunks for the current object have // Run a query to figure out which chunks for the current object have
// hits for this keyword. // hits for this keyword.
Keyword keywordQuery = new Keyword(keyword, isLiteral); Keyword keywordQuery = new Keyword(keyword, isLiteral, true);
KeywordSearchQuery chunksQuery = new LuceneQuery(new KeywordList(Arrays.asList(keywordQuery)), keywordQuery); KeywordSearchQuery chunksQuery = new LuceneQuery(new KeywordList(Arrays.asList(keywordQuery)), keywordQuery);
chunksQuery.escape(); chunksQuery.escape();
chunksQuery.addFilter(new KeywordQueryFilter(FilterType.CHUNK, this.objectId)); chunksQuery.addFilter(new KeywordQueryFilter(FilterType.CHUNK, this.objectId));

View File

@ -39,38 +39,6 @@ class Keyword {
private final String listName; private final String listName;
private final String originalTerm; private final String originalTerm;
/**
* Constructs a representation of a keyword for which to search. The search
* term for the keyword may be either a literal term that will be treated as
* a whole word, or a regex.
*
* @param searchTerm The search term for the keyword.
* @param isLiteral Whether or not the search term is a literal term that
* will be treated as a whole word, instead of a regex.
*/
Keyword(String searchTerm, boolean isLiteral) {
this.searchTerm = searchTerm;
this.isLiteral = isLiteral;
this.isWholeWord = true;
this.listName = "";
this.originalTerm = searchTerm;
}
Keyword(String searchTerm, boolean isLiteral, String listName, String originalTerm) {
this.searchTerm = searchTerm;
this.isLiteral = isLiteral;
this.isWholeWord = true;
this.listName = listName;
this.originalTerm = originalTerm;
}
Keyword(String searchTerm, boolean isLiteral, boolean isWholeWord, String listName, String originalTerm) {
this.searchTerm = searchTerm;
this.isLiteral = isLiteral;
this.isWholeWord = isWholeWord;
this.listName = listName;
this.originalTerm = originalTerm;
}
/** /**
* Constructs a representation of a keyword for which to search. The search * Constructs a representation of a keyword for which to search. The search
* term may be either a literal term, to be treated as either a whole word * term may be either a literal term, to be treated as either a whole word
@ -88,7 +56,37 @@ class Keyword {
this.isLiteral = isLiteral; this.isLiteral = isLiteral;
this.isWholeWord = isWholeWord; this.isWholeWord = isWholeWord;
this.listName = ""; this.listName = "";
this.originalTerm = searchTerm; this.originalTerm = searchTerm;
}
/**
* Constructs a representation of a keyword for which to search. The search
* term may be either a literal term, to be treated as either a whole word
* or as a substring, or a regex.
*
* NOTE: The addition of keyword list name and original search term was
* added to facilitate proper de-duping of results of periodic keyword
* searches that does not lose any keyword hits. Without this addition when
* using substring search feature during ingest, if there are multiple searches
* on differnt keyword lists that produce the same keyword hit, that hit is
* only going to be displayed in results of one of the list. For example,
* two substring searches, such as "pass" and "enger", will be missing one
* copy of any shared entries (i.e., "passenger" will only show up on one
* list). See JIRA story 2495.
*
* @param searchTerm The search term.
* @param isLiteral Whether or not the search term is a literal term,
* instead of a regex.
* @param isWholeWord Whether or not the search term, if it is a literal
* search term, should be treated as a whole word rather
* than a substring.
*/
Keyword(String searchTerm, boolean isLiteral, boolean isWholeWord, String listName, String originalTerm) {
this.searchTerm = searchTerm;
this.isLiteral = isLiteral;
this.isWholeWord = isWholeWord;
this.listName = listName;
this.originalTerm = originalTerm;
} }
/** /**
@ -106,7 +104,7 @@ class Keyword {
* @param keywordType The artifact attribute type. * @param keywordType The artifact attribute type.
*/ */
Keyword(String searchTerm, boolean isLiteral, BlackboardAttribute.ATTRIBUTE_TYPE artifactAtrributeType) { Keyword(String searchTerm, boolean isLiteral, BlackboardAttribute.ATTRIBUTE_TYPE artifactAtrributeType) {
this(searchTerm, isLiteral); this(searchTerm, isLiteral, true);
this.artifactAtrributeType = artifactAtrributeType; this.artifactAtrributeType = artifactAtrributeType;
} }

View File

@ -181,7 +181,7 @@ class LuceneQuery implements KeywordSearchQuery {
QueryResults results = new QueryResults(this); QueryResults results = new QueryResults(this);
//in case of single term literal query there is only 1 term //in case of single term literal query there is only 1 term
results.addResult(new Keyword(originalKeyword.getSearchTerm(), true, originalKeyword.getListName(), originalKeyword.getOriginalTerm()), matches); results.addResult(new Keyword(originalKeyword.getSearchTerm(), true, true, originalKeyword.getListName(), originalKeyword.getOriginalTerm()), matches);
return results; return results;
} }

View File

@ -204,7 +204,7 @@ final class RegexQuery implements KeywordSearchQuery {
try { try {
List<KeywordHit> keywordHits = createKeywordHits(resultDoc); List<KeywordHit> keywordHits = createKeywordHits(resultDoc);
for (KeywordHit hit : keywordHits) { for (KeywordHit hit : keywordHits) {
hitsMultiMap.put(new Keyword(hit.getHit(), true, originalKeyword.getListName(), originalKeyword.getOriginalTerm()), hit); hitsMultiMap.put(new Keyword(hit.getHit(), true, true, originalKeyword.getListName(), originalKeyword.getOriginalTerm()), hit);
} }
} catch (TskException ex) { } catch (TskException ex) {
// //

View File

@ -306,14 +306,14 @@ final class TermsComponentQuery implements KeywordSearchQuery {
* query. * query.
*/ */
String escapedTerm = KeywordSearchUtil.escapeLuceneQuery(term.getTerm()); String escapedTerm = KeywordSearchUtil.escapeLuceneQuery(term.getTerm());
LuceneQuery termQuery = new LuceneQuery(keywordList, new Keyword(escapedTerm, true)); LuceneQuery termQuery = new LuceneQuery(keywordList, new Keyword(escapedTerm, true, true));
filters.forEach(termQuery::addFilter); // This appears to be unused filters.forEach(termQuery::addFilter); // This appears to be unused
QueryResults termQueryResult = termQuery.performQuery(); QueryResults termQueryResult = termQuery.performQuery();
Set<KeywordHit> termHits = new HashSet<>(); Set<KeywordHit> termHits = new HashSet<>();
for (Keyword word : termQueryResult.getKeywords()) { for (Keyword word : termQueryResult.getKeywords()) {
termHits.addAll(termQueryResult.getResults(word)); termHits.addAll(termQueryResult.getResults(word));
} }
results.addResult(new Keyword(term.getTerm(), false, originalKeyword.getListName(), originalKeyword.getOriginalTerm()), new ArrayList<>(termHits)); results.addResult(new Keyword(term.getTerm(), false, true, originalKeyword.getListName(), originalKeyword.getOriginalTerm()), new ArrayList<>(termHits));
} }
return results; return results;
} }

View File

@ -201,7 +201,7 @@ final class XmlKeywordSearchList extends KeywordSearchList {
Keyword keyword; Keyword keyword;
String whole = wordEl.getAttribute(KEYWORD_WHOLE_ATTR); String whole = wordEl.getAttribute(KEYWORD_WHOLE_ATTR);
if (whole.equals("")) { if (whole.equals("")) {
keyword = new Keyword(wordEl.getTextContent(), isLiteral); keyword = new Keyword(wordEl.getTextContent(), isLiteral, true);
} else { } else {
boolean isWhole = whole.equals("true"); boolean isWhole = whole.equals("true");
keyword = new Keyword(wordEl.getTextContent(), isLiteral, isWhole); keyword = new Keyword(wordEl.getTextContent(), isLiteral, isWhole);