19 package org.sleuthkit.autopsy.keywordsearch;
21 import org.apache.commons.lang3.math.NumberUtils;
22 import org.apache.solr.common.SolrInputDocument;
23 import org.openide.util.NbBundle;
27 import java.util.ArrayList;
28 import java.util.List;
30 import java.util.Optional;
35 class LanguageSpecificContentIndexingHelper {
37 private final LanguageDetector languageDetector =
new LanguageDetector();
39 Optional<Language> detectLanguageIfNeeded(Chunker.Chunk chunk) throws NoOpenCoreException {
40 double indexSchemaVersion = NumberUtils.toDouble(KeywordSearch.getServer().getIndexInfo().getSchemaVersion());
41 if (2.2 <= indexSchemaVersion) {
42 return languageDetector.detect(chunk.toString());
44 return Optional.empty();
48 void updateLanguageSpecificFields(Map<String, Object> fields, Chunker.Chunk chunk, Language language) {
49 List<String> values =
new ArrayList<>();
50 values.add(chunk.toString());
51 if (fields.containsKey(Server.Schema.FILE_NAME.toString())) {
52 values.add(fields.get(Server.Schema.FILE_NAME.toString()).toString());
56 fields.put(Server.Schema.CONTENT_JA.toString(), values);
57 fields.put(Server.Schema.LANGUAGE.toString(), language.getValue());
60 void indexMiniChunk(Chunker.Chunk chunk, String sourceName, Map<String, Object> fields, String baseChunkID, Language language)
61 throws Ingester.IngesterException {
63 SolrInputDocument updateDoc =
new SolrInputDocument();
64 for (String key : fields.keySet()) {
65 updateDoc.addField(key, fields.get(key));
69 updateDoc.setField(Server.Schema.ID.toString(), MiniChunkHelper.getChunkIdString(baseChunkID));
72 updateDoc.addField(Server.Schema.CONTENT_JA.toString(), chunk.toString().substring(chunk.getBaseChunkLength()));
73 updateDoc.addField(Server.Schema.LANGUAGE.toString(), language.getValue());
75 TimingMetric metric = HealthMonitor.getTimingMetric(
"Solr: Index chunk");
77 KeywordSearch.getServer().addDocument(updateDoc);
78 HealthMonitor.submitTimingMetric(metric);
80 }
catch (KeywordSearchModuleException | NoOpenCoreException ex) {
81 throw new Ingester.IngesterException(
82 NbBundle.getMessage(Ingester.class,
"Ingester.ingest.exception.err.msg", sourceName), ex);