mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 18:17:43 +00:00
Added result paging support.
This commit is contained in:
parent
681699467d
commit
c1f326775a
@ -31,10 +31,12 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery.SortClause;
|
||||||
import org.apache.solr.client.solrj.SolrRequest;
|
import org.apache.solr.client.solrj.SolrRequest;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.common.SolrDocument;
|
import org.apache.solr.common.SolrDocument;
|
||||||
import org.apache.solr.common.SolrDocumentList;
|
import org.apache.solr.common.SolrDocumentList;
|
||||||
|
import org.apache.solr.common.params.CursorMarkParams;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
|
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
|
||||||
@ -74,7 +76,7 @@ final class RegexQuery implements KeywordSearchQuery {
|
|||||||
private final Keyword keyword;
|
private final Keyword keyword;
|
||||||
private String field = Server.Schema.CONTENT_STR.toString();
|
private String field = Server.Schema.CONTENT_STR.toString();
|
||||||
private final String keywordString;
|
private final String keywordString;
|
||||||
static final private int MAX_RESULTS = 20000;
|
static final private int MAX_RESULTS = 5;
|
||||||
private boolean escaped;
|
private boolean escaped;
|
||||||
private String escapedQuery;
|
private String escapedQuery;
|
||||||
|
|
||||||
@ -163,8 +165,6 @@ final class RegexQuery implements KeywordSearchQuery {
|
|||||||
+ (queryStringContainsWildcardPrefix ? "" : ".*") + getQueryString()
|
+ (queryStringContainsWildcardPrefix ? "" : ".*") + getQueryString()
|
||||||
+ (queryStringContainsWildcardSuffix ? "" : ".*") + "/");
|
+ (queryStringContainsWildcardSuffix ? "" : ".*") + "/");
|
||||||
|
|
||||||
solrQuery.setRows(MAX_RESULTS);
|
|
||||||
|
|
||||||
// Set the fields we want to have returned by the query.
|
// Set the fields we want to have returned by the query.
|
||||||
if (KeywordSearchSettings.getShowSnippets()) {
|
if (KeywordSearchSettings.getShowSnippets()) {
|
||||||
solrQuery.setFields(Server.Schema.CONTENT_STR.toString(), Server.Schema.ID.toString());
|
solrQuery.setFields(Server.Schema.CONTENT_STR.toString(), Server.Schema.ID.toString());
|
||||||
@ -175,18 +175,21 @@ final class RegexQuery implements KeywordSearchQuery {
|
|||||||
.map(KeywordQueryFilter::toString)
|
.map(KeywordQueryFilter::toString)
|
||||||
.forEach(solrQuery::addFilterQuery);
|
.forEach(solrQuery::addFilterQuery);
|
||||||
|
|
||||||
int start = 0;
|
solrQuery.setRows(MAX_RESULTS);
|
||||||
SolrDocumentList resultList = null;
|
// Setting the sort order is necessary for cursor based paging to work.
|
||||||
// cycle through results in sets of MAX_RESULTS
|
solrQuery.setSort(SortClause.asc(Server.Schema.ID.toString()));
|
||||||
while (resultList == null || start < resultList.getNumFound()) {
|
|
||||||
solrQuery.setStart(start);
|
|
||||||
|
|
||||||
|
String cursorMark = CursorMarkParams.CURSOR_MARK_START;
|
||||||
|
SolrDocumentList resultList = null;
|
||||||
|
boolean allResultsProcessed = false;
|
||||||
|
|
||||||
|
while (!allResultsProcessed) {
|
||||||
try {
|
try {
|
||||||
final QueryResponse response = solrServer.query(solrQuery, SolrRequest.METHOD.POST);
|
solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
|
||||||
|
QueryResponse response = solrServer.query(solrQuery, SolrRequest.METHOD.POST);
|
||||||
resultList = response.getResults();
|
resultList = response.getResults();
|
||||||
|
|
||||||
for (SolrDocument resultDoc : resultList) {
|
for (SolrDocument resultDoc : resultList) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<KeywordHit> keywordHits = createKeywordHits(resultDoc);
|
List<KeywordHit> keywordHits = createKeywordHits(resultDoc);
|
||||||
for (KeywordHit hit : keywordHits) {
|
for (KeywordHit hit : keywordHits) {
|
||||||
@ -196,13 +199,18 @@ final class RegexQuery implements KeywordSearchQuery {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String nextCursorMark = response.getNextCursorMark();
|
||||||
|
if (cursorMark.equals(nextCursorMark)) {
|
||||||
|
allResultsProcessed = true;
|
||||||
|
}
|
||||||
|
cursorMark = nextCursorMark;
|
||||||
} catch (KeywordSearchModuleException ex) {
|
} catch (KeywordSearchModuleException ex) {
|
||||||
LOGGER.log(Level.SEVERE, "Error executing Lucene Solr Query: " + keywordString, ex); //NON-NLS
|
LOGGER.log(Level.SEVERE, "Error executing Lucene Solr Query: " + keywordString, ex); //NON-NLS
|
||||||
MessageNotifyUtil.Notify.error(NbBundle.getMessage(Server.class, "Server.query.exception.msg", keywordString), ex.getCause().getMessage());
|
MessageNotifyUtil.Notify.error(NbBundle.getMessage(Server.class, "Server.query.exception.msg", keywordString), ex.getCause().getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
start = start + MAX_RESULTS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Keyword k : hitsMultMap.keySet()) {
|
for (Keyword k : hitsMultMap.keySet()) {
|
||||||
results.addResult(k, hitsMultMap.get(k));
|
results.addResult(k, hitsMultMap.get(k));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user