diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java index 6c65f075ef..9e99394a34 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/LuceneQuery.java @@ -23,8 +23,10 @@ import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.logging.Level; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrRequest.METHOD; import org.apache.solr.client.solrj.response.QueryResponse; @@ -221,11 +223,19 @@ class LuceneQuery implements KeywordSearchQuery { * will get picked up in the next one. */ final String docId = resultDoc.getFieldValue(Server.Schema.ID.toString()).toString(); final Integer chunkSize = (Integer) resultDoc.getFieldValue(Server.Schema.CHUNK_SIZE.toString()); - final String content_str = resultDoc.get(Server.Schema.CONTENT_STR.toString()).toString(); + String content_str = Objects.toString(resultDoc.get(Server.Schema.CONTENT_STR.toString()), null); - int firstOccurence = content_str.indexOf(strippedQueryString); - if (chunkSize != null && firstOccurence < chunkSize) { + double indexSchemaVersion = NumberUtils.toDouble(KeywordSearch.getServer().getIndexInfo().getSchemaVersion()); + if (indexSchemaVersion < 2.0) { + //old schema versions don't support chunk_size or the content_str fields, so just accept hits matches.add(createKeywordtHit(highlightResponse, docId)); + } else { + //for new schemas, check that the hit is before the chunk/window boundary. + int firstOccurence = StringUtils.indexOf(content_str, strippedQueryString); + //there is no chunksize field for "parent" entries in the index + if (chunkSize != null && firstOccurence < chunkSize) { + matches.add(createKeywordtHit(highlightResponse, docId)); + } } } catch (TskException ex) { return matches; diff --git a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/RegexQuery.java b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/RegexQuery.java index aa11182b86..0c5ac166f2 100644 --- a/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/RegexQuery.java +++ b/KeywordSearch/src/org/sleuthkit/autopsy/keywordsearch/RegexQuery.java @@ -243,6 +243,7 @@ final class RegexQuery implements KeywordSearchQuery { while (hitMatcher.find(offset)) { StringBuilder snippet = new StringBuilder(); + //"parent" entries in the index don't have chunk size, so just accept those hits if (chunkSize != null && hitMatcher.start() >= chunkSize) { break; }