Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IndexFinder.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.io.File;
22 import java.nio.file.Paths;
23 import java.util.List;
24 import java.util.logging.Level;
25 import org.apache.commons.lang.math.NumberUtils;
29 
33 class IndexFinder {
34 
35  private static final Logger logger = Logger.getLogger(IndexFinder.class.getName());
36  private static final String KWS_OUTPUT_FOLDER_NAME = "keywordsearch";
37  private static final String KWS_DATA_FOLDER_NAME = "data";
38  private static final String INDEX_FOLDER_NAME = "index";
39  private static final String CURRENT_SOLR_VERSION = "8";
40  private static final String CURRENT_SOLR_SCHEMA_VERSION = "2.3";
41 
42  static String getCurrentSolrVersion() {
43  return CURRENT_SOLR_VERSION;
44  }
45 
46  static String getCurrentSchemaVersion() {
47  return CURRENT_SOLR_SCHEMA_VERSION;
48  }
49 
50  static Index findLatestVersionIndexDir(List<Index> allIndexes) {
51  for (Index index : allIndexes) {
52  if (index.getSolrVersion().equals(CURRENT_SOLR_VERSION) && index.getSchemaVersion().equals(CURRENT_SOLR_SCHEMA_VERSION)) {
53  return index;
54  }
55  }
56  return null;
57  }
58 
59  static Index createLatestVersionIndexDir(Case theCase) throws AutopsyService.AutopsyServiceException {
60  String indexFolderName = "solr" + CURRENT_SOLR_VERSION + "_schema" + CURRENT_SOLR_SCHEMA_VERSION;
61  // new index should be stored in "\ModuleOutput\keywordsearch\data\solrX_schemaY\index"
62  File targetDirPath = Paths.get(theCase.getModuleDirectory(), KWS_OUTPUT_FOLDER_NAME, KWS_DATA_FOLDER_NAME, indexFolderName, INDEX_FOLDER_NAME).toFile(); //NON-NLS
63  if (!targetDirPath.mkdirs()) {
64  logger.log(Level.SEVERE, "Unable to create index directory: {0}", targetDirPath.toString());
65  throw new AutopsyService.AutopsyServiceException("Unable to create text index directory " + targetDirPath.getAbsolutePath());
66  }
67  return new Index(targetDirPath.getAbsolutePath(), CURRENT_SOLR_VERSION, CURRENT_SOLR_SCHEMA_VERSION, "", theCase.getName());
68  }
69 
70  static Index identifyIndexToUse(List<Index> allIndexes) {
71  /*
72  * NOTE: All of the following paths are valid multi-user index paths:
73  * (Solr 4, schema 1.8)
74  * X:\Case\ingest1\ModuleOutput\keywordsearch\data\index
75  * X:\Case\ingest4\ModuleOutput\keywordsearch\data\solr6_schema2.0\index
76  * X:\Case\ingest4\ModuleOutput\keywordsearch\data\solr6_schema1.8\index
77  * X:\Case\ingest4\ModuleOutput\keywordsearch\data\solr7_schema2.0\index
78  */
79  Index bestCandidateIndex = null;
80  double solrVerFound = 0.0;
81  double schemaVerFound = 0.0;
82  for (Index index : allIndexes) {
83  // higher Solr version takes priority because it may negate index upgrade
84  if (NumberUtils.toDouble(index.getSolrVersion()) >= solrVerFound) {
85  // if same solr version, pick the one with highest schema version
86  if (NumberUtils.toDouble(index.getSchemaVersion()) >= schemaVerFound) {
87  bestCandidateIndex = index;
88  solrVerFound = NumberUtils.toDouble(index.getSolrVersion());
89  schemaVerFound = NumberUtils.toDouble(index.getSchemaVersion());
90  }
91  }
92  }
93  return bestCandidateIndex;
94  }
95 }

Copyright © 2012-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.