19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import org.apache.commons.lang.math.NumberUtils;
30 private final String indexPath;
31 private final String schemaVersion;
32 private final String solrVersion;
33 private final String indexName;
34 private static final String DEFAULT_CORE_NAME =
"text_index";
47 Index(String indexPath, String solrVersion, String schemaVersion, String coreName, String caseName) {
48 this.indexPath = indexPath;
49 this.solrVersion = solrVersion;
50 this.schemaVersion = schemaVersion;
51 if (coreName == null || coreName.isEmpty()) {
53 coreName = createCoreName(caseName);
55 this.indexName = coreName;
65 private String createCoreName(String caseName) {
66 String coreName = sanitizeCoreName(caseName);
67 SimpleDateFormat dateFormat =
new SimpleDateFormat(
"yyyyMMdd_HHmmss");
68 Date date =
new Date();
69 return coreName +
"_" + dateFormat.format(date);
85 static private String sanitizeCoreName(String coreName) {
91 result = coreName.replaceAll(
"[^-.0-9A-Z_a-z]",
"_");
94 result = result.toLowerCase();
97 if (result.length() > 0 && (result.codePointAt(0) ==
'-')) {
98 result =
"_" + result;
101 if (result.isEmpty()) {
102 result = DEFAULT_CORE_NAME;
111 String getIndexPath() {
118 String getSchemaVersion() {
119 return schemaVersion;
125 String getSolrVersion() {
132 String getIndexName() {
144 boolean isCompatible(String version) {
146 int currentMajorVersion = NumberUtils.toInt(schemaVersion.substring(0, schemaVersion.indexOf(
'.')));
147 int givenMajorVersion = NumberUtils.toInt(version.substring(0, version.indexOf(
'.')));
149 return currentMajorVersion == givenMajorVersion;