19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import org.apache.commons.lang.math.NumberUtils;
31 private final String indexPath;
32 private final String schemaVersion;
33 private final String solrVersion;
34 private final String indexName;
35 private static final String DEFAULT_CORE_NAME =
"text_index";
36 private final UNCPathUtilities uncPathUtilities =
new UNCPathUtilities();
49 Index(String indexPath, String solrVersion, String schemaVersion, String coreName, String caseName) {
50 this.indexPath = uncPathUtilities.convertPathToUNC(indexPath);
51 this.solrVersion = solrVersion;
52 this.schemaVersion = schemaVersion;
53 if (coreName == null || coreName.isEmpty()) {
55 coreName = createCoreName(caseName);
57 this.indexName = coreName;
67 private String createCoreName(String caseName) {
68 String coreName = sanitizeCoreName(caseName);
69 SimpleDateFormat dateFormat =
new SimpleDateFormat(
"yyyyMMdd_HHmmss");
70 Date date =
new Date();
71 return coreName +
"_" + dateFormat.format(date);
87 static private String sanitizeCoreName(String coreName) {
93 result = coreName.replaceAll(
"[^-.0-9A-Z_a-z]",
"_");
96 result = result.toLowerCase();
99 if (result.length() > 0 && (result.codePointAt(0) ==
'-')) {
100 result =
"_" + result;
103 if (result.isEmpty()) {
104 result = DEFAULT_CORE_NAME;
113 String getIndexPath() {
120 String getSchemaVersion() {
121 return schemaVersion;
127 String getSolrVersion() {
134 String getIndexName() {
146 boolean isCompatible(String version) {
148 int currentMajorVersion = NumberUtils.toInt(schemaVersion.substring(0, schemaVersion.indexOf(
'.')));
149 int givenMajorVersion = NumberUtils.toInt(version.substring(0, version.indexOf(
'.')));
151 return currentMajorVersion == givenMajorVersion;