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;
37 final class QueryTermHelper {
39 private QueryTermHelper() {}
48 final Map<String, List<String>> fieldTermsMap =
new HashMap<>();
57 static Result parse(String query, List<Server.Schema> fields)
throws KeywordSearchModuleException, NoOpenCoreException {
58 Server server = KeywordSearch.getServer();
60 FieldAnalysisRequest request =
new FieldAnalysisRequest();
61 for (Server.Schema field : fields) {
62 request.addFieldName(field.toString());
67 request.setFieldValue(
"");
68 request.setQuery(query);
70 FieldAnalysisResponse response =
new FieldAnalysisResponse();
72 response.setResponse(server.request(request));
73 }
catch (SolrServerException e) {
74 throw new KeywordSearchModuleException(e);
77 Result result =
new Result();
78 for (Map.Entry<String, FieldAnalysisResponse.Analysis> entry : response.getAllFieldNameAnalysis()) {
79 Iterator<AnalysisResponseBase.AnalysisPhase> it = entry.getValue().getQueryPhases().iterator();
82 AnalysisResponseBase.AnalysisPhase lastPhase = null;
83 while (it.hasNext()) {
84 lastPhase = it.next();
87 if (lastPhase != null) {
88 List<String> tokens = lastPhase.getTokens().stream().map(AnalysisResponseBase.TokenInfo::getText).collect(Collectors.toList());
89 result.fieldTermsMap.put(entry.getKey(), tokens);