KeywordTokenizer.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.azure.search.documents.implementation.converters.KeywordTokenizerHelper;
  6. import com.fasterxml.jackson.annotation.JsonCreator;
  7. import com.fasterxml.jackson.annotation.JsonProperty;

  8. /**
  9.  * Emits the entire input as a single token. This tokenizer is implemented
  10.  * using Apache Lucene.
  11.  */
  12. @Fluent
  13. public final class KeywordTokenizer extends LexicalTokenizer {
  14.     private String odataType;

  15.     /*
  16.      * The maximum token length. Default is 256. Tokens longer than the maximum
  17.      * length are split. The maximum token length that can be used is 300
  18.      * characters.
  19.      */
  20.     @JsonProperty(value = "maxTokenLength")
  21.     private Integer maxTokenLength;

  22.     static {
  23.         KeywordTokenizerHelper.setAccessor(new KeywordTokenizerHelper.KeywordTokenizerAccessor() {
  24.             @Override
  25.             public void setODataType(KeywordTokenizer keywordTokenizer, String odataType) {
  26.                 keywordTokenizer.setODataType(odataType);
  27.             }

  28.             @Override
  29.             public String getODataType(KeywordTokenizer keywordTokenizer) {
  30.                 return keywordTokenizer.getODataType();
  31.             }
  32.         });
  33.     }

  34.     /**
  35.      * Constructor of {@link KeywordTokenizer}.
  36.      *
  37.      * @param name The name of the tokenizer. It must only contain letters, digits, spaces,
  38.      * dashes or underscores, can only start and end with alphanumeric
  39.      * characters, and is limited to 128 characters.
  40.      */
  41.     @JsonCreator
  42.     public KeywordTokenizer(@JsonProperty(value = "name", required = true) String name) {
  43.         super(name);
  44.         odataType = "#Microsoft.Azure.Search.KeywordTokenizerV2";
  45.     }
  46.     /**
  47.      * Get the maxTokenLength property: The maximum token length. Default is
  48.      * 256. Tokens longer than the maximum length are split. The maximum token
  49.      * length that can be used is 300 characters.
  50.      *
  51.      * @return the maxTokenLength value.
  52.      */
  53.     public Integer getMaxTokenLength() {
  54.         return this.maxTokenLength;
  55.     }

  56.     /**
  57.      * Set the maxTokenLength property: The maximum token length. Default is
  58.      * 256. Tokens longer than the maximum length are split. The maximum token
  59.      * length that can be used is 300 characters.
  60.      *
  61.      * @param maxTokenLength the maxTokenLength value to set.
  62.      * @return the KeywordTokenizerV2 object itself.
  63.      */
  64.     public KeywordTokenizer setMaxTokenLength(Integer maxTokenLength) {
  65.         this.maxTokenLength = maxTokenLength;
  66.         return this;
  67.     }

  68.     /**
  69.      * The private setter to set the odataType property
  70.      * via {@link KeywordTokenizerHelper.KeywordTokenizerAccessor}.
  71.      *
  72.      * @param odataType The OData type.
  73.      */
  74.     private void setODataType(String odataType) {
  75.         this.odataType = odataType;
  76.     }

  77.     /**
  78.      * The private getter to get the odataType property
  79.      * via {@link KeywordTokenizerHelper.KeywordTokenizerAccessor}.
  80.      *
  81.      * @return The OData type.
  82.      */
  83.     private String getODataType() {
  84.         return this.odataType;
  85.     }
  86. }