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

com.couchbase.client.java.manager.search.SearchIndex Maven / Gradle / Ivy

There is a newer version: 3.7.5
Show newest version
/*
 * Copyright (c) 2018 Couchbase, Inc.
 *
 * 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.couchbase.client.java.manager.search;

import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonCreator;
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonProperty;
import com.couchbase.client.core.error.InvalidArgumentException;
import com.couchbase.client.core.json.Mapper;

import java.util.Collections;
import java.util.Map;


/**
 * A full text search index definition.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class SearchIndex {

  private final String name;
  private final String sourceName;

  private String uuid;
  private String type;
  private Map params;
  private String sourceUuid;
  private Map sourceParams;
  private String sourceType;
  private Map planParams;

  public SearchIndex(final String name, final String sourceName) {
    this.name = name;
    this.sourceName = sourceName;
  }

  @JsonCreator
  public SearchIndex(
    @JsonProperty("uuid") String uuid,
    @JsonProperty("name") String name,
    @JsonProperty("type") String type,
    @JsonProperty("params") Map params,
    @JsonProperty("sourceUUID") String sourceUuid,
    @JsonProperty("sourceName") String sourceName,
    @JsonProperty("sourceParams") Map sourceParams,
    @JsonProperty("sourceType") String sourceType,
    @JsonProperty("planParams") Map planParams) {
    this.uuid = uuid;
    this.name = name;
    this.sourceName = sourceName;
    this.type = type;
    this.params = params;
    this.sourceUuid = sourceUuid;
    this.sourceParams = sourceParams;
    this.sourceType = sourceType;
    this.planParams = planParams;
  }

  /**
   * Takes a encoded index definition and turns it into a {@link SearchIndex} which can be used.
   *
   * @param input the encoded JSON index definition.
   * @return the instantiated index.
   */
  public static SearchIndex fromJson(final String input) {
    try {
      return Mapper.decodeInto(input, SearchIndex.class);
    } catch (Exception ex) {
      throw InvalidArgumentException.fromMessage("Could not decode search index JSON", ex);
    }
  }

  public String name() {
    return name;
  }

  public String uuid() {
    return uuid;
  }

  public SearchIndex uuid(String uuid) {
    this.uuid = uuid;
    return this;
  }

  /**
   * Allows to unset the UUID from an index definition.
   *
   * This method is especially useful if you are creating an index definition from a index JSON blob and you want
   * to create the index rather than modify it. If the index is not created and you leave the UUID in, the request
   * will fail with an {@link com.couchbase.client.core.error.IndexNotFoundException}.
   */
  public SearchIndex unsetUuid() {
    this.uuid = null;
    return this;
  }

  public String sourceName() {
    return sourceName;
  }

  public String type() {
    return type;
  }

  public Map params() {
    return params == null ? Collections.emptyMap() : params;
  }

  public SearchIndex params(Map params) {
    this.params = params;
    return this;
  }

  public String sourceUuid() {
    return sourceUuid;
  }

  public SearchIndex sourceUuid(String sourceUuid) {
    this.sourceUuid = sourceUuid;
    return this;
  }

  public Map sourceParams() {
    return sourceParams == null ? Collections.emptyMap() : sourceParams;
  }

  public SearchIndex sourceParams(Map sourceParams) {
    this.sourceParams = sourceParams;
    return this;
  }

  public String sourceType() {
    return sourceType;
  }

  public SearchIndex sourceType(String sourceType) {
    this.sourceType = sourceType;
    return this;
  }

  public Map planParams() {
    return planParams == null ? Collections.emptyMap() : planParams;
  }

  public SearchIndex planParams(Map planParams) {
    this.planParams = planParams;
    return this;
  }

  public String toJson() {
    return SearchIndexManagerUtil.convert(this).toJson();
  }

  @Override
  public String toString() {
    return "SearchIndex{" +
      "uuid='" + uuid + '\'' +
      ", name='" + name + '\'' +
      ", sourceName='" + sourceName + '\'' +
      ", type='" + type + '\'' +
      ", params=" + params +
      ", sourceUuid='" + sourceUuid + '\'' +
      ", sourceParams=" + sourceParams +
      ", sourceType='" + sourceType + '\'' +
      ", planParams=" + planParams +
      '}';
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy