Improve documnetation of KeywordSearchQuery method

This commit is contained in:
Richard Cordovano 2017-10-14 08:06:15 -04:00
parent 8ac6e71afe
commit 32af6d3b49
5 changed files with 66 additions and 19 deletions

View File

@ -101,20 +101,20 @@ interface KeywordSearchQuery {
String getEscapedQueryString(); String getEscapedQueryString();
/** /**
* Converts the keyword hits for a given search term into artifacts. * Posts a keyword hit artifact to the blackboard for a given keyword hit.
* *
* @param content The Content object associated with the hit. * @param content The text source object for the hit.
* @param foundKeyword The keyword that was found by the search, this may be * @param foundKeyword The keyword that was found by the search, this may be
* different than the Keyword that was searched if, for * different than the Keyword that was searched if, for
* example, it was a RegexQuery. * example, it was a RegexQuery.
* @param hit The keyword hit. * @param hit The keyword hit.
* @param snippet The document snippet that contains the hit. * @param snippet A snippet from the text that contains the hit.
* @param listName The name of the keyword list that contained the * @param listName The name of the keyword list that contained the
* keyword for which the hit was found. * keyword for which the hit was found.
* *
* *
* @return The newly created artifact or Null if there was a problem * @return The newly created artifact or null if there was a problem
* creating it. * creating it.
*/ */
BlackboardArtifact writeSingleFileHitsToBlackBoard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName); BlackboardArtifact postKeywordHitToBlackboard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName);
} }

View File

@ -52,8 +52,8 @@ class LuceneQuery implements KeywordSearchQuery {
private static final Logger logger = Logger.getLogger(LuceneQuery.class.getName()); private static final Logger logger = Logger.getLogger(LuceneQuery.class.getName());
private String keywordStringEscaped; private String keywordStringEscaped;
private boolean isEscaped; private boolean isEscaped;
private final Keyword originalKeyword ; private final Keyword originalKeyword;
private final KeywordList keywordList ; private final KeywordList keywordList;
private final List<KeywordQueryFilter> filters = new ArrayList<>(); private final List<KeywordQueryFilter> filters = new ArrayList<>();
private String field = null; private String field = null;
private static final int MAX_RESULTS_PER_CURSOR_MARK = 512; private static final int MAX_RESULTS_PER_CURSOR_MARK = 512;
@ -70,7 +70,7 @@ class LuceneQuery implements KeywordSearchQuery {
LuceneQuery(KeywordList keywordList, Keyword keyword) { LuceneQuery(KeywordList keywordList, Keyword keyword) {
this.keywordList = keywordList; this.keywordList = keywordList;
this.originalKeyword = keyword; this.originalKeyword = keyword;
this.keywordStringEscaped = this.originalKeyword.getSearchTerm(); this.keywordStringEscaped = this.originalKeyword.getSearchTerm();
} }
@Override @Override
@ -191,8 +191,24 @@ class LuceneQuery implements KeywordSearchQuery {
return StringUtils.isNotBlank(originalKeyword.getSearchTerm()); return StringUtils.isNotBlank(originalKeyword.getSearchTerm());
} }
/**
* Posts a keyword hit artifact to the blackboard for a given keyword hit.
*
* @param content The text source object for the hit.
* @param foundKeyword The keyword that was found by the search, this may be
* different than the Keyword that was searched if, for
* example, it was a RegexQuery.
* @param hit The keyword hit.
* @param snippet A snippet from the text that contains the hit.
* @param listName The name of the keyword list that contained the
* keyword for which the hit was found.
*
*
* @return The newly created artifact or null if there was a problem
* creating it.
*/
@Override @Override
public BlackboardArtifact writeSingleFileHitsToBlackBoard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName) { public BlackboardArtifact postKeywordHitToBlackboard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName) {
final String MODULE_NAME = KeywordSearchModuleFactory.getModuleName(); final String MODULE_NAME = KeywordSearchModuleFactory.getModuleName();
Collection<BlackboardAttribute> attributes = new ArrayList<>(); Collection<BlackboardAttribute> attributes = new ArrayList<>();
@ -225,11 +241,9 @@ class LuceneQuery implements KeywordSearchQuery {
} }
} }
hit.getArtifactID().ifPresent(artifactID hit.getArtifactID().ifPresent(artifactID
-> attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT, MODULE_NAME, artifactID)) -> attributes.add(new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT, MODULE_NAME, artifactID))
); );
try { try {
bba.addAttributes(attributes); //write out to bb bba.addAttributes(attributes); //write out to bb
@ -398,10 +412,10 @@ class LuceneQuery implements KeywordSearchQuery {
return EscapeUtil.unEscapeHtml(contentHighlights.get(0)).trim(); return EscapeUtil.unEscapeHtml(contentHighlights.get(0)).trim();
} }
} catch (NoOpenCoreException ex) { } catch (NoOpenCoreException ex) {
logger.log(Level.SEVERE, "Error executing Lucene Solr Query: " + query +". Solr doc id " + solrObjectId + ", chunkID " + chunkID , ex); //NON-NLS logger.log(Level.SEVERE, "Error executing Lucene Solr Query: " + query + ". Solr doc id " + solrObjectId + ", chunkID " + chunkID, ex); //NON-NLS
throw ex; throw ex;
} catch (KeywordSearchModuleException ex) { } catch (KeywordSearchModuleException ex) {
logger.log(Level.SEVERE, "Error executing Lucene Solr Query: " + query +". Solr doc id " + solrObjectId + ", chunkID " + chunkID , ex); //NON-NLS logger.log(Level.SEVERE, "Error executing Lucene Solr Query: " + query + ". Solr doc id " + solrObjectId + ", chunkID " + chunkID, ex); //NON-NLS
return ""; return "";
} }
} }

View File

@ -63,6 +63,8 @@ class QueryResults {
* blackboard, sending messages about the search hits to the ingest inbox, * blackboard, sending messages about the search hits to the ingest inbox,
* and publishing an event to notify subscribers of the blackboard posts. * and publishing an event to notify subscribers of the blackboard posts.
* *
* The KeywordSearchQuery is used to do the blackboard posts.
*
* @param query The query. * @param query The query.
*/ */
QueryResults(KeywordSearchQuery query) { QueryResults(KeywordSearchQuery query) {
@ -219,7 +221,7 @@ class QueryResults {
/* /*
* Post an artifact for the hit to the blackboard. * Post an artifact for the hit to the blackboard.
*/ */
BlackboardArtifact artifact = query.writeSingleFileHitsToBlackBoard(content, keyword, hit, snippet, query.getKeywordList().getName()); BlackboardArtifact artifact = query.postKeywordHitToBlackboard(content, keyword, hit, snippet, query.getKeywordList().getName());
if (null == artifact) { if (null == artifact) {
logger.log(Level.SEVERE, "Error posting keyword hit artifact for keyword {0} in {1} to the blackboard", new Object[]{keyword.toString(), content}); //NON-NLS logger.log(Level.SEVERE, "Error posting keyword hit artifact for keyword {0} in {1} to the blackboard", new Object[]{keyword.toString(), content}); //NON-NLS
} }

View File

@ -401,8 +401,24 @@ final class RegexQuery implements KeywordSearchQuery {
return escapedQuery; return escapedQuery;
} }
/**
* Posts a keyword hit artifact to the blackboard for a given keyword hit.
*
* @param content The text source object for the hit.
* @param foundKeyword The keyword that was found by the search, this may be
* different than the Keyword that was searched if, for
* example, it was a RegexQuery.
* @param hit The keyword hit.
* @param snippet A snippet from the text that contains the hit.
* @param listName The name of the keyword list that contained the
* keyword for which the hit was found.
*
*
* @return The newly created artifact or null if there was a problem
* creating it.
*/
@Override @Override
public BlackboardArtifact writeSingleFileHitsToBlackBoard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName) { public BlackboardArtifact postKeywordHitToBlackboard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName) {
final String MODULE_NAME = KeywordSearchModuleFactory.getModuleName(); final String MODULE_NAME = KeywordSearchModuleFactory.getModuleName();
if (content == null) { if (content == null) {

View File

@ -79,8 +79,8 @@ final class TermsComponentQuery implements KeywordSearchQuery {
* digit is 2 through 6 * digit is 2 through 6
* *
*/ */
static final Pattern CREDIT_CARD_NUM_PATTERN = static final Pattern CREDIT_CARD_NUM_PATTERN
Pattern.compile("(?<ccn>[2-6]([ -]?[0-9]){11,18})"); = Pattern.compile("(?<ccn>[2-6]([ -]?[0-9]){11,18})");
static final Pattern CREDIT_CARD_TRACK1_PATTERN = Pattern.compile( static final Pattern CREDIT_CARD_TRACK1_PATTERN = Pattern.compile(
/* /*
* Track 1 is alphanumeric. * Track 1 is alphanumeric.
@ -124,7 +124,6 @@ final class TermsComponentQuery implements KeywordSearchQuery {
+ "?)?)?)?)?)?"); //close nested optional groups //NON-NLS + "?)?)?)?)?)?"); //close nested optional groups //NON-NLS
static final BlackboardAttribute.Type KEYWORD_SEARCH_DOCUMENT_ID = new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_DOCUMENT_ID); static final BlackboardAttribute.Type KEYWORD_SEARCH_DOCUMENT_ID = new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_DOCUMENT_ID);
/** /**
* Constructs an object that implements a regex query that will be performed * Constructs an object that implements a regex query that will be performed
* as a two step operation. In the first step, the Solr terms component is * as a two step operation. In the first step, the Solr terms component is
@ -325,8 +324,24 @@ final class TermsComponentQuery implements KeywordSearchQuery {
return results; return results;
} }
/**
* Posts a keyword hit artifact to the blackboard for a given keyword hit.
*
* @param content The text source object for the hit.
* @param foundKeyword The keyword that was found by the search, this may be
* different than the Keyword that was searched if, for
* example, it was a RegexQuery.
* @param hit The keyword hit.
* @param snippet A snippet from the text that contains the hit.
* @param listName The name of the keyword list that contained the
* keyword for which the hit was found.
*
*
* @return The newly created artifact or null if there was a problem
* creating it.
*/
@Override @Override
public BlackboardArtifact writeSingleFileHitsToBlackBoard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName) { public BlackboardArtifact postKeywordHitToBlackboard(Content content, Keyword foundKeyword, KeywordHit hit, String snippet, String listName) {
/* /*
* Create either a "plain vanilla" keyword hit artifact with keyword and * Create either a "plain vanilla" keyword hit artifact with keyword and
* regex attributes, or a credit card account artifact with attributes * regex attributes, or a credit card account artifact with attributes