IndexingParameters.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.core.util.CoreUtils;
  6. import com.fasterxml.jackson.annotation.JsonProperty;

  7. import java.util.HashMap;
  8. import java.util.Map;

  9. /**
  10.  * Represents parameters for indexer execution.
  11.  */
  12. @Fluent
  13. public final class IndexingParameters {
  14.     /*
  15.      * The number of items that are read from the data source and indexed as a
  16.      * single batch in order to improve performance. The default depends on the
  17.      * data source type.
  18.      */
  19.     @JsonProperty(value = "batchSize")
  20.     private Integer batchSize;

  21.     /*
  22.      * The maximum number of items that can fail indexing for indexer execution
  23.      * to still be considered successful. -1 means no limit. Default is 0.
  24.      */
  25.     @JsonProperty(value = "maxFailedItems")
  26.     private Integer maxFailedItems;

  27.     /*
  28.      * The maximum number of items in a single batch that can fail indexing for
  29.      * the batch to still be considered successful. -1 means no limit. Default
  30.      * is 0.
  31.      */
  32.     @JsonProperty(value = "maxFailedItemsPerBatch")
  33.     private Integer maxFailedItemsPerBatch;

  34.     /*
  35.      * A dictionary of indexer-specific configuration properties. Each name is
  36.      * the name of a specific property. Each value must be of a primitive type.
  37.      */
  38.     @JsonProperty(value = "configuration")
  39.     private Map<String, Object> configuration;

  40.     /**
  41.      * Get the batchSize property: The number of items that are read from the data source and indexed as a single batch
  42.      * in order to improve performance. The default depends on the data source type.
  43.      *
  44.      * @return the batchSize value.
  45.      */
  46.     public Integer getBatchSize() {
  47.         return this.batchSize;
  48.     }

  49.     /**
  50.      * Set the batchSize property: The number of items that are read from the data source and indexed as a single batch
  51.      * in order to improve performance. The default depends on the data source type.
  52.      *
  53.      * @param batchSize the batchSize value to set.
  54.      * @return the IndexingParameters object itself.
  55.      */
  56.     public IndexingParameters setBatchSize(Integer batchSize) {
  57.         this.batchSize = batchSize;
  58.         return this;
  59.     }

  60.     /**
  61.      * Get the maxFailedItems property: The maximum number of items that can fail indexing for indexer execution to
  62.      * still be considered successful. -1 means no limit. Default is 0.
  63.      *
  64.      * @return the maxFailedItems value.
  65.      */
  66.     public Integer getMaxFailedItems() {
  67.         return this.maxFailedItems;
  68.     }

  69.     /**
  70.      * Set the maxFailedItems property: The maximum number of items that can fail indexing for indexer execution to
  71.      * still be considered successful. -1 means no limit. Default is 0.
  72.      *
  73.      * @param maxFailedItems the maxFailedItems value to set.
  74.      * @return the IndexingParameters object itself.
  75.      */
  76.     public IndexingParameters setMaxFailedItems(Integer maxFailedItems) {
  77.         this.maxFailedItems = maxFailedItems;
  78.         return this;
  79.     }

  80.     /**
  81.      * Get the maxFailedItemsPerBatch property: The maximum number of items in a single batch that can fail indexing for
  82.      * the batch to still be considered successful. -1 means no limit. Default is 0.
  83.      *
  84.      * @return the maxFailedItemsPerBatch value.
  85.      */
  86.     public Integer getMaxFailedItemsPerBatch() {
  87.         return this.maxFailedItemsPerBatch;
  88.     }

  89.     /**
  90.      * Set the maxFailedItemsPerBatch property: The maximum number of items in a single batch that can fail indexing for
  91.      * the batch to still be considered successful. -1 means no limit. Default is 0.
  92.      *
  93.      * @param maxFailedItemsPerBatch the maxFailedItemsPerBatch value to set.
  94.      * @return the IndexingParameters object itself.
  95.      */
  96.     public IndexingParameters setMaxFailedItemsPerBatch(Integer maxFailedItemsPerBatch) {
  97.         this.maxFailedItemsPerBatch = maxFailedItemsPerBatch;
  98.         return this;
  99.     }

  100.     /**
  101.      * Get the configuration property: A dictionary of indexer-specific configuration properties. Each name is the name
  102.      * of a specific property. Each value must be of a primitive type.
  103.      *
  104.      * @return the configuration value.
  105.      */
  106.     public Map<String, Object> getConfiguration() {
  107.         return this.configuration;
  108.     }

  109.     /**
  110.      * Set the configuration property: A dictionary of indexer-specific configuration properties. Each name is the name
  111.      * of a specific property. Each value must be of a primitive type.
  112.      *
  113.      * @param configuration the configuration value to set.
  114.      * @return the IndexingParameters object itself.
  115.      */
  116.     public IndexingParameters setConfiguration(Map<String, Object> configuration) {
  117.         this.configuration = configuration;
  118.         return this;
  119.     }

  120.     /**
  121.      * Get the configuration property: A dictionary of indexer-specific configuration properties. Each name is the name
  122.      * of a specific property. Each value must be of a primitive type.
  123.      *
  124.      * @return the configuration value.
  125.      */
  126.     public IndexingParametersConfiguration getIndexingParametersConfiguration() {
  127.         if (CoreUtils.isNullOrEmpty(this.configuration)) {
  128.             return null;
  129.         }

  130.         IndexingParametersConfiguration configuration = new IndexingParametersConfiguration();

  131.         for (Map.Entry<String, Object> kvp : this.configuration.entrySet()) {
  132.             String key = kvp.getKey();
  133.             if (key == null) {
  134.                 continue;
  135.             }

  136.             String value = (kvp.getValue() == null) ? null : String.valueOf(kvp.getValue());
  137.             switch (key) {
  138.                 case "parsingMode":
  139.                     configuration.setParsingMode(BlobIndexerParsingMode.fromString(value));
  140.                     break;

  141.                 case "excludedFileNameExtensions":
  142.                     configuration.setExcludedFileNameExtensions(value);
  143.                     break;

  144.                 case "indexedFileNameExtensions":
  145.                     configuration.setIndexedFileNameExtensions(value);
  146.                     break;

  147.                 case "failOnUnsupportedContentType":
  148.                     configuration.setFailOnUnsupportedContentType(Boolean.valueOf(value));
  149.                     break;

  150.                 case "failOnUnprocessableDocument":
  151.                     configuration.setFailOnUnprocessableDocument(Boolean.valueOf(value));
  152.                     break;

  153.                 case "indexStorageMetadataOnlyForOversizedDocuments":
  154.                     configuration.setIndexStorageMetadataOnlyForOversizedDocuments(Boolean.valueOf(value));
  155.                     break;

  156.                 case "delimitedTextHeaders":
  157.                     configuration.setDelimitedTextHeaders(value);
  158.                     break;

  159.                 case "delimitedTextDelimiter":
  160.                     configuration.setDelimitedTextDelimiter(value);
  161.                     break;

  162.                 case "firstLineContainsHeaders":
  163.                     configuration.setFirstLineContainsHeaders(Boolean.valueOf(value));
  164.                     break;

  165.                 case "documentRoot":
  166.                     configuration.setDocumentRoot(value);
  167.                     break;

  168.                 case "dataToExtract":
  169.                     configuration.setDataToExtract(BlobIndexerDataToExtract.fromString(value));
  170.                     break;

  171.                 case "imageAction":
  172.                     configuration.setImageAction(BlobIndexerImageAction.fromString(value));
  173.                     break;

  174.                 case "allowSkillsetToReadFileData":
  175.                     configuration.setAllowSkillsetToReadFileData(Boolean.valueOf(value));
  176.                     break;

  177.                 case "pdfTextRotationAlgorithm":
  178.                     configuration.setPdfTextRotationAlgorithm(BlobIndexerPdfTextRotationAlgorithm.fromString(value));
  179.                     break;

  180.                 case "executionEnvironment":
  181.                     configuration.setExecutionEnvironment(IndexerExecutionEnvironment.fromString(value));
  182.                     break;

  183.                 case "queryTimeout":
  184.                     configuration.setQueryTimeout(value);
  185.                     break;

  186.                 default:
  187.                     configuration.setAdditionalProperties(key, value);
  188.                     break;
  189.             }
  190.         }

  191.         return configuration;
  192.     }

  193.     /**
  194.      * Set the configuration property: A dictionary of indexer-specific configuration properties. Each name is the name
  195.      * of a specific property. Each value must be of a primitive type.
  196.      *
  197.      * @param configuration the configuration value to set.
  198.      * @return the IndexingParameters object itself.
  199.      */
  200.     public IndexingParameters setIndexingParametersConfiguration(IndexingParametersConfiguration configuration) {
  201.         setConfigurationValue(configuration.getParsingMode(), "parsingMode");
  202.         setConfigurationValue(configuration.getExcludedFileNameExtensions(), "excludedFileNameExtensions");
  203.         setConfigurationValue(configuration.getIndexedFileNameExtensions(), "indexedFileNameExtensions");
  204.         setConfigurationValue(configuration.isFailOnUnsupportedContentType(), "failOnUnsupportedContentType");
  205.         setConfigurationValue(configuration.isFailOnUnprocessableDocument(), "failOnUnprocessableDocument");
  206.         setConfigurationValue(configuration.isIndexStorageMetadataOnlyForOversizedDocuments(),
  207.             "indexStorageMetadataOnlyForOversizedDocuments");
  208.         setConfigurationValue(configuration.getDelimitedTextHeaders(), "delimitedTextHeaders");
  209.         setConfigurationValue(configuration.getDelimitedTextDelimiter(), "delimitedTextDelimiter");
  210.         setConfigurationValue(configuration.isFirstLineContainsHeaders(), "firstLineContainsHeaders");
  211.         setConfigurationValue(configuration.getDocumentRoot(), "documentRoot");
  212.         setConfigurationValue(configuration.getDataToExtract(), "dataToExtract");
  213.         setConfigurationValue(configuration.getImageAction(), "imageAction");
  214.         setConfigurationValue(configuration.isAllowSkillsetToReadFileData(), "allowSkillsetToReadFileData");
  215.         setConfigurationValue(configuration.getPdfTextRotationAlgorithm(), "pdfTextRotationAlgorithm");
  216.         setConfigurationValue(configuration.getExecutionEnvironment(), "executionEnvironment");
  217.         setConfigurationValue(configuration.getQueryTimeout(), "queryTimeout");

  218.         Map<String, Object> additionalProperties = configuration.getAdditionalProperties();
  219.         if (!CoreUtils.isNullOrEmpty(additionalProperties)) {
  220.             this.configuration.putAll(additionalProperties);
  221.         }

  222.         return this;
  223.     }

  224.     private void setConfigurationValue(Object value, String key) {
  225.         if (value == null) {
  226.             return;
  227.         }

  228.         if (configuration == null) {
  229.             configuration = new HashMap<>();
  230.         }

  231.         configuration.put(key, String.valueOf(value));
  232.     }
  233. }