SearchIndex.java

  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.

  3. package com.azure.search.documents.indexes.models;

  4. import com.azure.core.annotation.Fluent;
  5. import com.fasterxml.jackson.annotation.JsonCreator;
  6. import com.fasterxml.jackson.annotation.JsonProperty;
  7. import com.fasterxml.jackson.annotation.JsonSetter;

  8. import java.util.Arrays;
  9. import java.util.List;

  10. /**
  11.  * Represents a search index definition, which describes the fields and search
  12.  * behavior of an index.
  13.  */
  14. @Fluent
  15. public final class SearchIndex {
  16.     /*
  17.      * The name of the index.
  18.      */
  19.     @JsonProperty(value = "name", required = true)
  20.     private String name;

  21.     /*
  22.      * The fields of the index.
  23.      */
  24.     @JsonProperty(value = "fields", required = true)
  25.     private List<SearchField> fields;

  26.     /*
  27.      * The scoring profiles for the index.
  28.      */
  29.     @JsonProperty(value = "scoringProfiles")
  30.     private List<ScoringProfile> scoringProfiles;

  31.     /*
  32.      * The name of the scoring profile to use if none is specified in the
  33.      * query. If this property is not set and no scoring profile is specified
  34.      * in the query, then default scoring (tf-idf) will be used.
  35.      */
  36.     @JsonProperty(value = "defaultScoringProfile")
  37.     private String defaultScoringProfile;

  38.     /*
  39.      * Options to control Cross-Origin Resource Sharing (CORS) for the index.
  40.      */
  41.     @JsonProperty(value = "corsOptions")
  42.     private CorsOptions corsOptions;

  43.     /*
  44.      * The suggesters for the index.
  45.      */
  46.     @JsonProperty(value = "suggesters")
  47.     private List<SearchSuggester> suggesters;

  48.     /*
  49.      * The analyzers for the index.
  50.      */
  51.     @JsonProperty(value = "analyzers")
  52.     private List<LexicalAnalyzer> analyzers;

  53.     /*
  54.      * The tokenizers for the index.
  55.      */
  56.     @JsonProperty(value = "tokenizers")
  57.     private List<LexicalTokenizer> tokenizers;

  58.     /*
  59.      * The token filters for the index.
  60.      */
  61.     @JsonProperty(value = "tokenFilters")
  62.     private List<TokenFilter> tokenFilters;

  63.     /*
  64.      * The character filters for the index.
  65.      */
  66.     @JsonProperty(value = "charFilters")
  67.     private List<CharFilter> charFilters;

  68.     /*
  69.      * The normalizers for the index.
  70.      */
  71.     @JsonProperty(value = "normalizers")
  72.     private List<LexicalNormalizer> normalizers;

  73.     /*
  74.      * A description of an encryption key that you create in Azure Key Vault.
  75.      * This key is used to provide an additional level of encryption-at-rest
  76.      * for your data when you want full assurance that no one, not even
  77.      * Microsoft, can decrypt your data in Azure Cognitive Search. Once you
  78.      * have encrypted your data, it will always remain encrypted. Azure
  79.      * Cognitive Search will ignore attempts to set this property to null. You
  80.      * can change this property as needed if you want to rotate your encryption
  81.      * key; Your data will be unaffected. Encryption with customer-managed keys
  82.      * is not available for free search services, and is only available for
  83.      * paid services created on or after January 1, 2019.
  84.      */
  85.     @JsonProperty(value = "encryptionKey")
  86.     private SearchResourceEncryptionKey encryptionKey;

  87.     /*
  88.      * The type of similarity algorithm to be used when scoring and ranking the
  89.      * documents matching a search query. The similarity algorithm can only be
  90.      * defined at index creation time and cannot be modified on existing
  91.      * indexes. If null, the ClassicSimilarity algorithm is used.
  92.      */
  93.     @JsonProperty(value = "similarity")
  94.     private SimilarityAlgorithm similarity;

  95.     /*
  96.      * Defines parameters for a search index that influence semantic
  97.      * capabilities.
  98.      */
  99.     @JsonProperty(value = "semantic")
  100.     private SemanticSettings semanticSettings;

  101.     /*
  102.      * The ETag of the index.
  103.      */
  104.     @JsonProperty(value = "@odata.etag")
  105.     private String eTag;


  106.     /**
  107.      * Constructor of {@link SearchIndex}.
  108.      * @param name The name of the index.
  109.      */
  110.     public SearchIndex(String name) {
  111.         this.name = name;
  112.     }

  113.     /**
  114.      * Constructor of {@link SearchIndex}.
  115.      * @param name The name of the index.
  116.      * @param fields The fields of the index.
  117.      */
  118.     @JsonCreator
  119.     public SearchIndex(
  120.         @JsonProperty(value = "name") String name,
  121.         @JsonProperty(value = "fields") List<SearchField> fields) {
  122.         this.name = name;
  123.         this.fields = fields;
  124.     }

  125.     /**
  126.      * Get the name property: The name of the index.
  127.      *
  128.      * @return the name value.
  129.      */
  130.     public String getName() {
  131.         return this.name;
  132.     }

  133.     /**
  134.      * Get the fields property: The fields of the index.
  135.      *
  136.      * @return the fields value.
  137.      */
  138.     public List<SearchField> getFields() {
  139.         return this.fields;
  140.     }

  141.     /**
  142.      * Set the fields property: The fields of the index.
  143.      *
  144.      * @param fields the fields value to set.
  145.      * @return the SearchIndex object itself.
  146.      */
  147.     public SearchIndex setFields(SearchField... fields) {
  148.         this.fields = (fields == null) ? null : Arrays.asList(fields);
  149.         return this;
  150.     }

  151.     /**
  152.      * Set the fields property: The fields of the index.
  153.      *
  154.      * @param fields the fields value to set.
  155.      * @return the SearchIndex object itself.
  156.      */
  157.     @JsonSetter
  158.     public SearchIndex setFields(List<SearchField> fields) {
  159.         this.fields = fields;
  160.         return this;
  161.     }

  162.     /**
  163.      * Get the scoringProfiles property: The scoring profiles for the index.
  164.      *
  165.      * @return the scoringProfiles value.
  166.      */
  167.     public List<ScoringProfile> getScoringProfiles() {
  168.         return this.scoringProfiles;
  169.     }

  170.     /**
  171.      * Set the scoringProfiles property: The scoring profiles for the index.
  172.      *
  173.      * @param scoringProfiles the scoringProfiles value to set.
  174.      * @return the SearchIndex object itself.
  175.      */
  176.     public SearchIndex setScoringProfiles(ScoringProfile... scoringProfiles) {
  177.         this.scoringProfiles = (scoringProfiles == null) ? null : Arrays.asList(scoringProfiles);
  178.         return this;
  179.     }

  180.     /**
  181.      * Set the scoringProfiles property: The scoring profiles for the index.
  182.      *
  183.      * @param scoringProfiles the scoringProfiles value to set.
  184.      * @return the SearchIndex object itself.
  185.      */
  186.     @JsonSetter
  187.     public SearchIndex setScoringProfiles(List<ScoringProfile> scoringProfiles) {
  188.         this.scoringProfiles = scoringProfiles;
  189.         return this;
  190.     }

  191.     /**
  192.      * Get the defaultScoringProfile property: The name of the scoring profile
  193.      * to use if none is specified in the query. If this property is not set
  194.      * and no scoring profile is specified in the query, then default scoring
  195.      * (tf-idf) will be used.
  196.      *
  197.      * @return the defaultScoringProfile value.
  198.      */
  199.     public String getDefaultScoringProfile() {
  200.         return this.defaultScoringProfile;
  201.     }

  202.     /**
  203.      * Set the defaultScoringProfile property: The name of the scoring profile
  204.      * to use if none is specified in the query. If this property is not set
  205.      * and no scoring profile is specified in the query, then default scoring
  206.      * (tf-idf) will be used.
  207.      *
  208.      * @param defaultScoringProfile the defaultScoringProfile value to set.
  209.      * @return the SearchIndex object itself.
  210.      */
  211.     public SearchIndex setDefaultScoringProfile(String defaultScoringProfile) {
  212.         this.defaultScoringProfile = defaultScoringProfile;
  213.         return this;
  214.     }

  215.     /**
  216.      * Get the corsOptions property: Options to control Cross-Origin Resource
  217.      * Sharing (CORS) for the index.
  218.      *
  219.      * @return the corsOptions value.
  220.      */
  221.     public CorsOptions getCorsOptions() {
  222.         return this.corsOptions;
  223.     }

  224.     /**
  225.      * Set the corsOptions property: Options to control Cross-Origin Resource
  226.      * Sharing (CORS) for the index.
  227.      *
  228.      * @param corsOptions the corsOptions value to set.
  229.      * @return the SearchIndex object itself.
  230.      */
  231.     public SearchIndex setCorsOptions(CorsOptions corsOptions) {
  232.         this.corsOptions = corsOptions;
  233.         return this;
  234.     }

  235.     /**
  236.      * Get the suggesters property: The suggesters for the index.
  237.      *
  238.      * @return the suggesters value.
  239.      */
  240.     public List<SearchSuggester> getSuggesters() {
  241.         return this.suggesters;
  242.     }

  243.     /**
  244.      * Set the suggesters property: The suggesters for the index.
  245.      *
  246.      * @param suggesters the suggesters value to set.
  247.      * @return the SearchIndex object itself.
  248.      */
  249.     public SearchIndex setSuggesters(SearchSuggester... suggesters) {
  250.         this.suggesters = (suggesters == null) ? null : Arrays.asList(suggesters);
  251.         return this;
  252.     }

  253.     /**
  254.      * Set the suggesters property: The suggesters for the index.
  255.      *
  256.      * @param suggesters the suggesters value to set.
  257.      * @return the SearchIndex object itself.
  258.      */
  259.     @JsonSetter
  260.     public SearchIndex setSuggesters(List<SearchSuggester> suggesters) {
  261.         this.suggesters = suggesters;
  262.         return this;
  263.     }

  264.     /**
  265.      * Get the analyzers property: The analyzers for the index.
  266.      *
  267.      * @return the analyzers value.
  268.      */
  269.     public List<LexicalAnalyzer> getAnalyzers() {
  270.         return this.analyzers;
  271.     }

  272.     /**
  273.      * Set the analyzers property: The analyzers for the index.
  274.      *
  275.      * @param analyzers the analyzers value to set.
  276.      * @return the SearchIndex object itself.
  277.      */
  278.     public SearchIndex setAnalyzers(LexicalAnalyzer... analyzers) {
  279.         this.analyzers = (analyzers == null) ? null : Arrays.asList(analyzers);
  280.         return this;
  281.     }

  282.     /**
  283.      * Set the analyzers property: The analyzers for the index.
  284.      *
  285.      * @param analyzers the analyzers value to set.
  286.      * @return the SearchIndex object itself.
  287.      */
  288.     @JsonSetter
  289.     public SearchIndex setAnalyzers(List<LexicalAnalyzer> analyzers) {
  290.         this.analyzers = analyzers;
  291.         return this;
  292.     }

  293.     /**
  294.      * Get the tokenizers property: The tokenizers for the index.
  295.      *
  296.      * @return the tokenizers value.
  297.      */
  298.     public List<LexicalTokenizer> getTokenizers() {
  299.         return this.tokenizers;
  300.     }

  301.     /**
  302.      * Set the tokenizers property: The tokenizers for the index.
  303.      *
  304.      * @param tokenizers the tokenizers value to set.
  305.      * @return the SearchIndex object itself.
  306.      */
  307.     public SearchIndex setTokenizers(LexicalTokenizer... tokenizers) {
  308.         this.tokenizers = (tokenizers == null) ? null : Arrays.asList(tokenizers);
  309.         return this;
  310.     }

  311.     /**
  312.      * Set the tokenizers property: The tokenizers for the index.
  313.      *
  314.      * @param tokenizers the tokenizers value to set.
  315.      * @return the SearchIndex object itself.
  316.      */
  317.     @JsonSetter
  318.     public SearchIndex setTokenizers(List<LexicalTokenizer> tokenizers) {
  319.         this.tokenizers = tokenizers;
  320.         return this;
  321.     }

  322.     /**
  323.      * Get the tokenFilters property: The token filters for the index.
  324.      *
  325.      * @return the tokenFilters value.
  326.      */
  327.     public List<TokenFilter> getTokenFilters() {
  328.         return this.tokenFilters;
  329.     }

  330.     /**
  331.      * Set the tokenFilters property: The token filters for the index.
  332.      *
  333.      * @param tokenFilters the tokenFilters value to set.
  334.      * @return the SearchIndex object itself.
  335.      */
  336.     public SearchIndex setTokenFilters(TokenFilter... tokenFilters) {
  337.         this.tokenFilters = (tokenFilters == null) ? null : Arrays.asList(tokenFilters);
  338.         return this;
  339.     }

  340.     /**
  341.      * Set the tokenFilters property: The token filters for the index.
  342.      *
  343.      * @param tokenFilters the tokenFilters value to set.
  344.      * @return the SearchIndex object itself.
  345.      */
  346.     @JsonSetter
  347.     public SearchIndex setTokenFilters(List<TokenFilter> tokenFilters) {
  348.         this.tokenFilters = tokenFilters;
  349.         return this;
  350.     }

  351.     /**
  352.      * Get the charFilters property: The character filters for the index.
  353.      *
  354.      * @return the charFilters value.
  355.      */
  356.     public List<CharFilter> getCharFilters() {
  357.         return this.charFilters;
  358.     }

  359.     /**
  360.      * Set the charFilters property: The character filters for the index.
  361.      *
  362.      * @param charFilters the charFilters value to set.
  363.      * @return the SearchIndex object itself.
  364.      */
  365.     public SearchIndex setCharFilters(CharFilter... charFilters) {
  366.         this.charFilters = (charFilters == null) ? null : Arrays.asList(charFilters);
  367.         return this;
  368.     }

  369.     /**
  370.      * Set the charFilters property: The character filters for the index.
  371.      *
  372.      * @param charFilters the charFilters value to set.
  373.      * @return the SearchIndex object itself.
  374.      */
  375.     @JsonSetter
  376.     public SearchIndex setCharFilters(List<CharFilter> charFilters) {
  377.         this.charFilters = charFilters;
  378.         return this;
  379.     }

  380.     /**
  381.      * Get the normalizers property: The normalizers for the index.
  382.      *
  383.      * @return the normalizers value.
  384.      */
  385.     public List<LexicalNormalizer> getNormalizers() {
  386.         return this.normalizers;
  387.     }

  388.     /**
  389.      * Set the normalizers property: The normalizers for the index.
  390.      *
  391.      * @param normalizers the normalizers value to set.
  392.      * @return the SearchIndex object itself.
  393.      */
  394.     public SearchIndex setNormalizers(LexicalNormalizer... normalizers) {
  395.         this.normalizers = (normalizers == null) ? null : Arrays.asList(normalizers);
  396.         return this;
  397.     }

  398.     /**
  399.      * Set the normalizers property: The normalizers for the index.
  400.      *
  401.      * @param normalizers the normalizers value to set.
  402.      * @return the SearchIndex object itself.
  403.      */
  404.     @JsonSetter
  405.     public SearchIndex setNormalizers(List<LexicalNormalizer> normalizers) {
  406.         this.normalizers = normalizers;
  407.         return this;
  408.     }

  409.     /**
  410.      * Get the encryptionKey property: A description of an encryption key that
  411.      * you create in Azure Key Vault. This key is used to provide an additional
  412.      * level of encryption-at-rest for your data when you want full assurance
  413.      * that no one, not even Microsoft, can decrypt your data in Azure
  414.      * Cognitive Search. Once you have encrypted your data, it will always
  415.      * remain encrypted. Azure Cognitive Search will ignore attempts to set
  416.      * this property to null. You can change this property as needed if you
  417.      * want to rotate your encryption key; Your data will be unaffected.
  418.      * Encryption with customer-managed keys is not available for free search
  419.      * services, and is only available for paid services created on or after
  420.      * January 1, 2019.
  421.      *
  422.      * @return the encryptionKey value.
  423.      */
  424.     public SearchResourceEncryptionKey getEncryptionKey() {
  425.         return this.encryptionKey;
  426.     }

  427.     /**
  428.      * Set the encryptionKey property: A description of an encryption key that
  429.      * you create in Azure Key Vault. This key is used to provide an additional
  430.      * level of encryption-at-rest for your data when you want full assurance
  431.      * that no one, not even Microsoft, can decrypt your data in Azure
  432.      * Cognitive Search. Once you have encrypted your data, it will always
  433.      * remain encrypted. Azure Cognitive Search will ignore attempts to set
  434.      * this property to null. You can change this property as needed if you
  435.      * want to rotate your encryption key; Your data will be unaffected.
  436.      * Encryption with customer-managed keys is not available for free search
  437.      * services, and is only available for paid services created on or after
  438.      * January 1, 2019.
  439.      *
  440.      * @param encryptionKey the encryptionKey value to set.
  441.      * @return the SearchIndex object itself.
  442.      */
  443.     public SearchIndex setEncryptionKey(SearchResourceEncryptionKey encryptionKey) {
  444.         this.encryptionKey = encryptionKey;
  445.         return this;
  446.     }

  447.     /**
  448.      * Get the similarity property: The type of similarity algorithm to be used
  449.      * when scoring and ranking the documents matching a search query. The
  450.      * similarity algorithm can only be defined at index creation time and
  451.      * cannot be modified on existing indexes. If null, the ClassicSimilarity
  452.      * algorithm is used.
  453.      *
  454.      * @return the similarity value.
  455.      */
  456.     public SimilarityAlgorithm getSimilarity() {
  457.         return this.similarity;
  458.     }

  459.     /**
  460.      * Set the similarity property: The type of similarity algorithm to be used
  461.      * when scoring and ranking the documents matching a search query. The
  462.      * similarity algorithm can only be defined at index creation time and
  463.      * cannot be modified on existing indexes. If null, the ClassicSimilarity
  464.      * algorithm is used.
  465.      *
  466.      * @param similarity the similarity value to set.
  467.      * @return the SearchIndex object itself.
  468.      */
  469.     public SearchIndex setSimilarity(SimilarityAlgorithm similarity) {
  470.         this.similarity = similarity;
  471.         return this;
  472.     }

  473.     /**
  474.      * Get the semanticSettings property: Defines parameters for a search index that influence semantic capabilities.
  475.      *
  476.      * @return the semanticSettings value.
  477.      */
  478.     public SemanticSettings getSemanticSettings() {
  479.         return this.semanticSettings;
  480.     }

  481.     /**
  482.      * Set the semanticSettings property: Defines parameters for a search index that influence semantic capabilities.
  483.      *
  484.      * @param semanticSettings the semanticSettings value to set.
  485.      * @return the SearchIndex object itself.
  486.      */
  487.     public SearchIndex setSemanticSettings(SemanticSettings semanticSettings) {
  488.         this.semanticSettings = semanticSettings;
  489.         return this;
  490.     }

  491.     /**
  492.      * Get the eTag property: The ETag of the index.
  493.      *
  494.      * @return the eTag value.
  495.      */
  496.     public String getETag() {
  497.         return this.eTag;
  498.     }

  499.     /**
  500.      * Set the eTag property: The ETag of the index.
  501.      *
  502.      * @param eTag the eTag value to set.
  503.      * @return the SearchIndex object itself.
  504.      */
  505.     public SearchIndex setETag(String eTag) {
  506.         this.eTag = eTag;
  507.         return this;
  508.     }
  509. }