- sb.append("}");
-
- sb.append("}");
- sb.append("}");
-
- return sb.toString();
- }
-
-
- /**
- * Constructs an ElasticSearch friendly custom filter definition.
- *
- * @param filter - The filter to generate ElasticSearch json for.
- * @param sb - The string builder to append the filter definition
- * to.
- */
- private void buildFilterEntry(FilterSchema filter, StringBuilder sb) {
-
- sb.append("\"" + filter.getName()).append("\": {");
-
- sb.append(filter.getConfiguration());
-
- sb.append("}");
- }
-
-
- /**
- * Constructs an ElasticSearch friendly custom analyzer definition.
- *
- * @param analyzer - The analyzer to generate ElasticSearch json for.
- * @param sb - The string builder to append the analyzer definition
- * to.
- */
- private void buildAnalyzerEntry(AnalyzerSchema analyzer, StringBuilder sb) {
-
- sb.append("\"").append(analyzer.getName()).append("\": {");
- sb.append("\"type\": \"custom\",");
- sb.append("\"tokenizer\": ").append("\"").append(analyzer.getTokenizer()).append("\",");
- sb.append("\"filter\": [");
- boolean firstFilter = true;
- for (String filter : analyzer.getFilters()) {
- if (!firstFilter) {
- sb.append(",");
- } else {
- firstFilter = false;
- }
- sb.append("\"").append(filter).append("\"");
+
+
+ /**
+ * Constructs a settings string that is readable by Elastic Search based on the contents of the filter and analyzer
+ * configuration files.
+ *
+ * @return Elastic Search formatted settings string.
+ */
+ public String buildEsIndexSettings() {
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("{");
+ sb.append("\"analysis\": {");
+
+ // Define the custom filters.
+ boolean atLeastOneFilter = false;
+ sb.append("\"filter\": {");
+ AtomicBoolean firstFilter = new AtomicBoolean(true);
+ for (FilterSchema filter : customFilters) {
+
+ // Append a comma before the next entry, unless it is the
+ // first one.
+ if (!firstFilter.compareAndSet(true, false)) {
+ sb.append(", ");
+ }
+
+ // Now, build the filter entry.
+ buildFilterEntry(filter, sb);
+ atLeastOneFilter = true;
+ }
+ sb.append((atLeastOneFilter) ? "}," : "}");
+
+ // Define the custom analyzers.
+ sb.append("\"analyzer\": {");
+ AtomicBoolean firstAnalyzer = new AtomicBoolean(true);
+ for (AnalyzerSchema analyzer : customAnalysers) {
+
+ // Prepend a comma before the entry, unless it is the
+ // first one.
+ if (!firstAnalyzer.compareAndSet(true, false)) {
+ sb.append(",");
+ }
+
+ // Now, construct the entry for this analyzer.
+ buildAnalyzerEntry(analyzer, sb);
+ }
+ sb.append("}");
+
+ sb.append("}");
+ sb.append("}");
+
+ return sb.toString();
+ }
+
+
+ /**
+ * Constructs an ElasticSearch friendly custom filter definition.
+ *
+ * @param filter - The filter to generate ElasticSearch json for.
+ * @param sb - The string builder to append the filter definition to.
+ */
+ private void buildFilterEntry(FilterSchema filter, StringBuilder sb) {
+
+ sb.append("\"" + filter.getName()).append("\": {");
+
+ sb.append(filter.getConfiguration());
+
+ sb.append("}");
+ }
+
+
+ /**
+ * Constructs an ElasticSearch friendly custom analyzer definition.
+ *
+ * @param analyzer - The analyzer to generate ElasticSearch json for.
+ * @param sb - The string builder to append the analyzer definition to.
+ */
+ private void buildAnalyzerEntry(AnalyzerSchema analyzer, StringBuilder sb) {
+
+ sb.append("\"").append(analyzer.getName()).append("\": {");
+ sb.append("\"type\": \"custom\",");
+ sb.append("\"tokenizer\": ").append("\"").append(analyzer.getTokenizer()).append("\",");
+ sb.append("\"filter\": [");
+ boolean firstFilter = true;
+ for (String filter : analyzer.getFilters()) {
+ if (!firstFilter) {
+ sb.append(",");
+ } else {
+ firstFilter = false;
+ }
+ sb.append("\"").append(filter).append("\"");
+ }
+ sb.append("]");
+ sb.append("}");