All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.honhimw.ms.model.Setting Maven / Gradle / Ivy

/*
 * 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 io.github.honhimw.ms.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 
 * {
 *   "displayedAttributes": [
 *     "*"
 *   ],
 *   "searchableAttributes": [
 *     "*"
 *   ],
 *   "filterableAttributes": [],
 *   "sortableAttributes": [],
 *   "rankingRules":
 *   [
 *     "words",
 *     "typo",
 *     "proximity",
 *     "attribute",
 *     "sort",
 *     "exactness"
 *   ],
 *   "stopWords": [],
 *   "nonSeparatorTokens": [],
 *   "separatorTokens": [],
 *   "dictionary": [],
 *   "synonyms": {},
 *   "distinctAttribute": null,
 *   "typoTolerance": {
 *     "enabled": true,
 *     "minWordSizeForTypos": {
 *       "oneTypo": 5,
 *       "twoTypos": 9
 *     },
 *     "disableOnWords": [],
 *     "disableOnAttributes": []
 *   },
 *   "faceting": {
 *     "maxValuesPerFacet": 100
 *   },
 *   "pagination": {
 *     "maxTotalHits": 1000
 *   },
 *   "proximityPrecision": "byWord"
 * }
 * 
* * @author hon_him * @since 2024-01-03 */ @Data @EqualsAndHashCode(callSuper = false) @NoArgsConstructor @AllArgsConstructor public class Setting implements Serializable { /** * Fields displayed in the returned documents", defaultValue = "[\"*\"] */ @Schema(description = "Fields displayed in the returned documents", defaultValue = "[\"*\"]") private List displayedAttributes; /** * Fields in which to search for matching query words sorted by order of importance", defaultValue = "[\"*\"] */ @Schema(description = "Fields in which to search for matching query words sorted by order of importance", defaultValue = "[\"*\"]") private List searchableAttributes; /** * Attributes to use as filters and facets", defaultValue = "[] */ @Schema(description = "Attributes to use as filters and facets", defaultValue = "[]") private List filterableAttributes; /** * Attributes to use when sorting search results", defaultValue = "[] */ @Schema(description = "Attributes to use when sorting search results", defaultValue = "[]") private List sortableAttributes; /** * List of ranking rules in order of importance", defaultValue = "[\"words\",\"typo\",\"proximity\",\"attribute\",\"sort\",\"exactness\"] */ @Schema(description = "List of ranking rules in order of importance", defaultValue = "[\"words\",\"typo\",\"proximity\",\"attribute\",\"sort\",\"exactness\"]") private List rankingRules; /** * List of words ignored by Meilisearch when present in search queries", defaultValue = "[] */ @Schema(description = "List of words ignored by Meilisearch when present in search queries", defaultValue = "[]") private List stopWords; /** * List of characters not delimiting where one term begins and ends", defaultValue = "[] */ @Schema(description = "List of characters not delimiting where one term begins and ends", defaultValue = "[]") private List nonSeparatorTokens; /** * List of characters delimiting where one term begins and ends", defaultValue = "[] */ @Schema(description = "List of characters delimiting where one term begins and ends", defaultValue = "[]") private List separatorTokens; /** * List of strings Meilisearch should parse as a single term", defaultValue = "[] */ @Schema(description = "List of strings Meilisearch should parse as a single term", defaultValue = "[]") private List dictionary; /** * List of associated words treated similarly", defaultValue = "{} */ @Schema(description = "List of associated words treated similarly", defaultValue = "{}") private Map> synonyms; /** * Search returns documents with distinct (different) values of the given field", defaultValue = "null */ @Schema(description = "Search returns documents with distinct (different) values of the given field", defaultValue = "null") private String distinctAttribute; /** * Typo tolerance settings", defaultValue = "default object */ @Schema(description = "Typo tolerance settings", defaultValue = "default object") private TypoTolerance typoTolerance; /** * Faceting settings", defaultValue = "default object */ @Schema(description = "Faceting settings", defaultValue = "default object") private Faceting faceting; /** * Pagination settings", defaultValue = "default object */ @Schema(description = "Pagination settings", defaultValue = "default object") private Pagination pagination; /** * Precision level when calculating the proximity ranking rule", defaultValue = "byWord */ @Schema(description = "Precision level when calculating the proximity ranking rule", defaultValue = "byWord") private ProximityPrecisionType proximityPrecision; /** * To use vector search, first configure the embedders index setting. You may configure multiple embedders for an index. */ @Schema(description = "To use vector search, first configure the embedders index setting. You may configure multiple embedders for an index.") private Map embedders; /** * To avoid any crash and performance issues, Meilisearch now stops search requests lasting more than 1500ms. * The default value of the searchCutoffMs setting is null and corresponds to 1500ms. */ @Schema(description = "To avoid any crash and performance issues, Meilisearch now stops search requests lasting more than 1500ms.", defaultValue = "null") private Integer searchCutoffMs; private Setting(Builder builder) { setDisplayedAttributes(builder.displayedAttributes); setSearchableAttributes(builder.searchableAttributes); setFilterableAttributes(builder.filterableAttributes); setSortableAttributes(builder.sortableAttributes); setRankingRules(builder.rankingRules); setStopWords(builder.stopWords); setNonSeparatorTokens(builder.nonSeparatorTokens); setSeparatorTokens(builder.separatorTokens); setDictionary(builder.dictionary); setSynonyms(builder.synonyms); setDistinctAttribute(builder.distinctAttribute); setTypoTolerance(builder.typoTolerance); setFaceting(builder.faceting); setPagination(builder.pagination); setProximityPrecision(builder.proximityPrecision); setEmbedders(builder.embedders); setSearchCutoffMs(builder.searchCutoffMs); } /** * Returns a default Setting object with all attributes set to their default values. * * @return a Setting object with default values for all attributes */ public static Setting defaultObject() { Setting setting = new Setting(); setting.setDisplayedAttributes(Stream.of("*").collect(Collectors.toList())); setting.setSearchableAttributes(Stream.of("*").collect(Collectors.toList())); setting.setFilterableAttributes(new ArrayList<>()); setting.setSortableAttributes(new ArrayList<>()); setting.setRankingRules(Stream.of(RankingRule.WORDS, RankingRule.TYPO, RankingRule.PROXIMITY, RankingRule.ATTRIBUTE, RankingRule.SORT, RankingRule.EXACTNESS).collect(Collectors.toList())); setting.setStopWords(new ArrayList<>()); setting.setSeparatorTokens(new ArrayList<>()); setting.setNonSeparatorTokens(new ArrayList<>()); setting.setDictionary(new ArrayList<>()); setting.setSynonyms(new HashMap<>()); setting.setDistinctAttribute(null); setting.setTypoTolerance(TypoTolerance.defaultObject()); setting.setFaceting(Faceting.defaultObject()); setting.setPagination(Pagination.defaultObject()); setting.setProximityPrecision(ProximityPrecisionType.BY_WORD); return setting; } /** * Creates and returns a new instance of the Builder class. * * @return a new instance of the Builder class */ public static Builder builder() { return new Builder(); } /** * {@code Setting} builder static inner class. */ public static final class Builder { private List displayedAttributes; private List searchableAttributes; private List filterableAttributes; private List sortableAttributes; private List rankingRules; private List stopWords; private List nonSeparatorTokens; private List separatorTokens; private List dictionary; private Map> synonyms; private String distinctAttribute; private TypoTolerance typoTolerance; private Faceting faceting; private Pagination pagination; private ProximityPrecisionType proximityPrecision; private Map embedders; private Integer searchCutoffMs; private Builder() { } /** * Sets the {@code displayedAttributes} and returns a reference to this Builder enabling method chaining. * * @param val the {@code displayedAttributes} to set * @return a reference to this Builder */ public Builder displayedAttributes(List val) { displayedAttributes = val; return this; } /** * Sets the {@code searchableAttributes} and returns a reference to this Builder enabling method chaining. * * @param val the {@code searchableAttributes} to set * @return a reference to this Builder */ public Builder searchableAttributes(List val) { searchableAttributes = val; return this; } /** * Sets the {@code filterableAttributes} and returns a reference to this Builder enabling method chaining. * * @param val the {@code filterableAttributes} to set * @return a reference to this Builder */ public Builder filterableAttributes(List val) { filterableAttributes = val; return this; } /** * Sets the {@code sortableAttributes} and returns a reference to this Builder enabling method chaining. * * @param val the {@code sortableAttributes} to set * @return a reference to this Builder */ public Builder sortableAttributes(List val) { sortableAttributes = val; return this; } /** * Sets the {@code rankingRules} and returns a reference to this Builder enabling method chaining. * * @param val the {@code rankingRules} to set * @return a reference to this Builder */ public Builder rankingRules(List val) { rankingRules = val; return this; } /** * Sets the {@code stopWords} and returns a reference to this Builder enabling method chaining. * * @param val the {@code stopWords} to set * @return a reference to this Builder */ public Builder stopWords(List val) { stopWords = val; return this; } /** * Sets the {@code nonSeparatorTokens} and returns a reference to this Builder enabling method chaining. * * @param val the {@code nonSeparatorTokens} to set * @return a reference to this Builder */ public Builder nonSeparatorTokens(List val) { nonSeparatorTokens = val; return this; } /** * Sets the {@code separatorTokens} and returns a reference to this Builder enabling method chaining. * * @param val the {@code separatorTokens} to set * @return a reference to this Builder */ public Builder separatorTokens(List val) { separatorTokens = val; return this; } /** * Sets the {@code dictionary} and returns a reference to this Builder enabling method chaining. * * @param val the {@code dictionary} to set * @return a reference to this Builder */ public Builder dictionary(List val) { dictionary = val; return this; } /** * Sets the {@code synonyms} and returns a reference to this Builder enabling method chaining. * * @param val the {@code synonyms} to set * @return a reference to this Builder */ public Builder synonyms(Map> val) { synonyms = val; return this; } /** * Sets the {@code distinctAttribute} and returns a reference to this Builder enabling method chaining. * * @param val the {@code distinctAttribute} to set * @return a reference to this Builder */ public Builder distinctAttribute(String val) { distinctAttribute = val; return this; } /** * Sets the {@code typoTolerance} and returns a reference to this Builder enabling method chaining. * * @param val the {@code typoTolerance} to set * @return a reference to this Builder */ public Builder typoTolerance(TypoTolerance val) { typoTolerance = val; return this; } /** * Sets the {@code faceting} and returns a reference to this Builder enabling method chaining. * * @param val the {@code faceting} to set * @return a reference to this Builder */ public Builder faceting(Faceting val) { faceting = val; return this; } /** * Sets the {@code pagination} and returns a reference to this Builder enabling method chaining. * * @param val the {@code pagination} to set * @return a reference to this Builder */ public Builder pagination(Pagination val) { pagination = val; return this; } /** * Sets the {@code proximityPrecision} and returns a reference to this Builder enabling method chaining. * * @param val the {@code proximityPrecision} to set * @return a reference to this Builder */ public Builder proximityPrecision(ProximityPrecisionType val) { proximityPrecision = val; return this; } /** * Sets the {@code embedders} and returns a reference to this Builder enabling method chaining. * * @param val the {@code embedders} to set * @return a reference to this Builder */ public Builder embedders(Map val) { embedders = val; return this; } /** * Sets the {@code searchCutoffMs} and returns a reference to this Builder enabling method chaining. * * @param val the {@code searchCutoffMs} to set * @return a reference to this Builder */ public Builder searchCutoffMs(Integer val) { searchCutoffMs = val; return this; } /** * Returns a {@code Setting} built from the parameters previously set. * * @return a {@code Setting} built with parameters of this {@code Setting.Builder} */ public Setting build() { return new Setting(this); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy