<commit_before>/*
 * Copyright 2021 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.b2international.snowowl.core.internal;

import static com.b2international.index.query.Expressions.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import com.b2international.commons.collections.Collections3;
import com.b2international.index.Analyzers;
import com.b2international.index.Doc;
import com.b2international.index.Normalizers;
import com.b2international.index.Script;
import com.b2international.index.mapping.Field;
import com.b2international.index.mapping.FieldAlias;
import com.b2international.index.mapping.FieldAlias.FieldAliasType;
import com.b2international.index.query.Expression;
import com.b2international.index.revision.RevisionBranchPoint;
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.repository.RevisionDocument;
import com.b2international.snowowl.core.request.TermFilter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

/**
 * @since 8.0
 */
@Doc(
	type = ResourceDocument.TYPE,
	revisionHash = {
		ResourceDocument.Fields.URL,
		ResourceDocument.Fields.TITLE,
		ResourceDocument.Fields.LANGUAGE,
		ResourceDocument.Fields.DESCRIPTION,
		ResourceDocument.Fields.STATUS,
		ResourceDocument.Fields.COPYRIGHT,
		ResourceDocument.Fields.OWNER,
		ResourceDocument.Fields.CONTACT,
		ResourceDocument.Fields.USAGE,
		ResourceDocument.Fields.PURPOSE,
	}
)
@JsonDeserialize(builder = ResourceDocument.Builder.class)
@Script(
		name="typeSort", 
		script=
		 "if (doc.resourceType.value.equals('bundles')) {"
		+ "	return '1'"
		+ "}"
		+ "if (doc.resourceType.value.equals('codesystems')) {"
		+ "	return '2'"
		+ "}"
		+ "if (doc.resourceType.value.equals('valuesets')) {"
		+ "	return '3'"
		+ "}"
		+ "if (doc.resourceType.value.equals('conceptmaps')) {"
		+ "	return '4'"
		+ "}"
		+ "return '5'")
public final class ResourceDocument extends RevisionDocument {

	public static final String TYPE = "resource";
	
	/**
	 * @since 8.0
	 */
	public static final class Fields extends RevisionDocument.Fields {

		// common resource fields
		public static final String RESOURCE_TYPE = "resourceType";
		public static final String URL = "url";
		public static final String TITLE = "title";<commit_msg>feat: make script more simple<commit_after>/*
 * Copyright 2021 B2i Healthcare Pte Ltd, http://b2i.sg
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.b2international.snowowl.core.internal;

import static com.b2international.index.query.Expressions.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import com.b2international.commons.collections.Collections3;
import com.b2international.index.Analyzers;
import com.b2international.index.Doc;
import com.b2international.index.Normalizers;
import com.b2international.index.Script;
import com.b2international.index.mapping.Field;
import com.b2international.index.mapping.FieldAlias;
import com.b2international.index.mapping.FieldAlias.FieldAliasType;
import com.b2international.index.query.Expression;
import com.b2international.index.revision.RevisionBranchPoint;
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.repository.RevisionDocument;
import com.b2international.snowowl.core.request.TermFilter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;

/**
 * @since 8.0
 */
@Doc(
	type = ResourceDocument.TYPE,
	revisionHash = {
		ResourceDocument.Fields.URL,
		ResourceDocument.Fields.TITLE,
		ResourceDocument.Fields.LANGUAGE,
		ResourceDocument.Fields.DESCRIPTION,
		ResourceDocument.Fields.STATUS,
		ResourceDocument.Fields.COPYRIGHT,
		ResourceDocument.Fields.OWNER,
		ResourceDocument.Fields.CONTACT,
		ResourceDocument.Fields.USAGE,
		ResourceDocument.Fields.PURPOSE,
	}
)
@JsonDeserialize(builder = ResourceDocument.Builder.class)
@Script(
		name="typeSort", 
		script=
		 "if (params.orderByType.containsKey(doc.resourceType.value)) {"
		+ "	return params.orderByType.get(doc.resourceType.value)"
		+ "}"
		+ "return '5'")
public final class ResourceDocument extends RevisionDocument {

	public static final String TYPE = "resource";
	
	/**
	 * @since 8.0
	 */
	public static final class Fields extends RevisionDocument.Fields {

		// common resource fields
		public static final String RESOURCE_TYPE = "resourceType";
		public static final String URL = "url";
		public static final String TITLE = "title";
{'fraction_non_alphanumeric': 0.10467596390484003, 'fraction_numerical': 0.010828547990155866, 'mean_word_length': 5.041625371655104, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1122230', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1748, 'n_words': 427}