package com.gentics.mesh.search.index.tag;

import static com.gentics.mesh.search.index.MappingHelper.NAME_KEY;
import static com.gentics.mesh.search.index.MappingHelper.NOT_ANALYZED;
import static com.gentics.mesh.search.index.MappingHelper.STRING;
import static com.gentics.mesh.search.index.MappingHelper.UUID_KEY;
import static com.gentics.mesh.search.index.MappingHelper.fieldType;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.gentics.mesh.core.data.Tag;
import com.gentics.mesh.core.data.TagFamily;
import com.gentics.mesh.search.index.AbstractTransformator;

import io.vertx.core.json.JsonObject;

/**
 * Transformator for tag search index documents.
 */
@Singleton
public class TagTransformator extends AbstractTransformator<Tag> {

	@Inject
	public TagTransformator() {
	}

	@Override
	public JsonObject toDocument(Tag tag) {
		JsonObject document = new JsonObject();
		Map<String, String> tagFields = new HashMap<>();
		tagFields.put(NAME_KEY, tag.getName());
		document.put("fields", tagFields);
		addBasicReferences(document, tag);
		addTagFamily(document, tag.getTagFamily());
		addProject(document, tag.getProject());
		return document;
	}

	public void addTagFamily(JsonObject document, TagFamily tagFamily) {
		JsonObject info = new JsonObject();
		info.put(NAME_KEY, tagFamily.getName());
		info.put(UUID_KEY, tagFamily.getUuid());
		document.put("tagFamily", info);
	}

	@Override
	public JsonObject getMappingProperties() {
		JsonObject props = new JsonObject();
		props.put(NAME_KEY, fieldType(STRING, NOT_ANALYZED));
		return props;
	}

}

@@ -37,16 +37,80 @@
 x.tag;%0A%0A
+import static com.gentics.mesh.search.index.MappingHelper.LONG;%0A
 import s
@@ -165,24 +165,24 @@
 r.NAME_KEY;%0A
-
 import stati
@@ -241,16 +241,82 @@
 ALYZED;%0A
+import static com.gentics.mesh.search.index.MappingHelper.OBJECT;%0A
 import s
@@ -515,57 +515,8 @@
 e;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 impo
@@ -1033,133 +1033,44 @@
 ;%0A%09%09
-Map%3CString, String%3E tagFields = new HashMap%3C%3E();%0A%09%09tagFields.put(NAME_KEY, tag.getName());%0A%09%09document.put(%22fields%22, tagFields
+document.put(NAME_KEY, tag.getName()
 );%0A%09
@@ -1543,16 +1543,16 @@
 ject();%0A
-
 %09%09props.
@@ -1595,24 +1595,825 @@
 ANALYZED));%0A
+%0A%09%09// tagFamily%0A%09%09JsonObject tagFamilyMapping = new JsonObject();%0A%09%09tagFamilyMapping.put(%22type%22, OBJECT);%0A%09%09JsonObject schemaMappingProperties = new JsonObject();%0A%09%09schemaMappingProperties.put(%22uuid%22, fieldType(STRING, NOT_ANALYZED));%0A%09%09schemaMappingProperties.put(%22name%22, fieldType(STRING, NOT_ANALYZED));%0A%09%09tagFamilyMapping.put(%22properties%22, schemaMappingProperties);%0A%09%09props.put(%22tagFamily%22, tagFamilyMapping);%0A%0A%09%09// project%0A%09%09JsonObject projectMapping = new JsonObject();%0A%09%09projectMapping.put(%22type%22, OBJECT);%0A%09%09JsonObject projectMappingProps = new JsonObject();%0A%09%09projectMappingProps.put(%22name%22, fieldType(STRING, NOT_ANALYZED));%0A%09%09projectMappingProps.put(%22uuid%22, fieldType(STRING, NOT_ANALYZED));%0A%09%09projectMapping.put(%22properties%22, projectMappingProps);%0A%09%09props.put(%22project%22, projectMapping);%0A%0A
 %09%09return pro

Update mapping for tag families