19 package org.sleuthkit.autopsy.keywordsearch;
21 import org.apache.solr.client.solrj.SolrServerException;
22 import org.apache.solr.client.solrj.request.FieldAnalysisRequest;
23 import org.apache.solr.client.solrj.response.AnalysisResponseBase;
24 import org.apache.solr.client.solrj.response.FieldAnalysisResponse;
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
30 import java.util.stream.Collectors;
31 import org.apache.solr.client.solrj.impl.BaseHttpSolrClient;
38 final class QueryTermHelper {
40 private QueryTermHelper() {}
49 final Map<String, List<String>> fieldTermsMap =
new HashMap<>();
58 static Result parse(String query, List<Server.Schema> fields)
throws KeywordSearchModuleException, NoOpenCoreException {
59 Server server = KeywordSearch.getServer();
61 FieldAnalysisRequest request =
new FieldAnalysisRequest();
62 for (Server.Schema field : fields) {
63 request.addFieldName(field.toString());
68 request.setFieldValue(
"");
69 request.setQuery(query);
71 FieldAnalysisResponse response =
new FieldAnalysisResponse();
73 response.setResponse(server.request(request));
74 }
catch (SolrServerException | BaseHttpSolrClient.RemoteSolrException e) {
75 throw new KeywordSearchModuleException(e);
78 Result result =
new Result();
79 for (Map.Entry<String, FieldAnalysisResponse.Analysis> entry : response.getAllFieldNameAnalysis()) {
80 Iterator<AnalysisResponseBase.AnalysisPhase> it = entry.getValue().getQueryPhases().iterator();
83 AnalysisResponseBase.AnalysisPhase lastPhase = null;
84 while (it.hasNext()) {
85 lastPhase = it.next();
88 if (lastPhase != null) {
89 List<String> tokens = lastPhase.getTokens().stream().map(AnalysisResponseBase.TokenInfo::getText).collect(Collectors.toList());
90 result.fieldTermsMap.put(entry.getKey(), tokens);