From 7daf4efc81bb83113199f39d6a76e78464d7b208 Mon Sep 17 00:00:00 2001 From: Pasin Suriyentrakorn Date: Thu, 8 Feb 2024 08:52:35 -0800 Subject: [PATCH] CBL-5374 : Use struct for all index configuration types (#3220) * Instead of using class, use struct for all index configuration types. * Update API doc. --- Objective-C/CBLFullTextIndexConfiguration.h | 3 ++ Objective-C/CBLValueIndexConfiguration.h | 3 ++ Swift/IndexConfiguration.swift | 51 ++++++++------------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/Objective-C/CBLFullTextIndexConfiguration.h b/Objective-C/CBLFullTextIndexConfiguration.h index 3d3bc6b9f..705d837d7 100644 --- a/Objective-C/CBLFullTextIndexConfiguration.h +++ b/Objective-C/CBLFullTextIndexConfiguration.h @@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN +/** + Configuration for creating full-text indexes. + */ @interface CBLFullTextIndexConfiguration : CBLIndexConfiguration /** diff --git a/Objective-C/CBLValueIndexConfiguration.h b/Objective-C/CBLValueIndexConfiguration.h index 803d0eb61..376d857fc 100644 --- a/Objective-C/CBLValueIndexConfiguration.h +++ b/Objective-C/CBLValueIndexConfiguration.h @@ -22,6 +22,9 @@ NS_ASSUME_NONNULL_BEGIN +/** + Configuration for creating value indexes. + */ @interface CBLValueIndexConfiguration : CBLIndexConfiguration /** diff --git a/Swift/IndexConfiguration.swift b/Swift/IndexConfiguration.swift index e8e5d3822..849851512 100644 --- a/Swift/IndexConfiguration.swift +++ b/Swift/IndexConfiguration.swift @@ -19,65 +19,52 @@ import Foundation +/// Configuration for creating indexes. public protocol IndexConfiguration { } -public class FullTextIndexConfiguration: IndexConfiguration, IndexConfigConvertable { - +/// Configuration for creating full-text indexes. +public struct FullTextIndexConfiguration: IndexConfiguration, IndexConfigConvertable { /// Gets the expressions to use to create the index. - public var expressions: [String] { - return self.impl.expressions - } + public let expressions: [String] /// Set the true value to ignore accents/diacritical marks. /// The default value is ``FullTextIndexConfiguration.defaultIgnoreAccents``. - public var ignoreAccents: Bool { - return self.impl.ignoreAccents - } + public let ignoreAccents: Bool /// The language code which is an ISO-639 language such as "en", "fr", etc. /// Setting the language code affects how word breaks and word stems are parsed. /// Without setting the value, the current locale's language will be used. Setting /// a nil or "" value to disable the language features. - public var language: String? { - return self.impl.language - } + public var language: String? /// Constructor for creating a full-text index by using an array of N1QL expression strings - public init(_ expressions: [String], - ignoreAccents: Bool? = FullTextIndexConfiguration.defaultIgnoreAccents, - language: String? = nil) { - self.impl = CBLFullTextIndexConfiguration(expression: expressions, - ignoreAccents: ignoreAccents ?? FullTextIndexConfiguration.defaultIgnoreAccents, - language: language) + public init(_ expressions: [String], ignoreAccents: Bool? = FullTextIndexConfiguration.defaultIgnoreAccents, language: String? = nil) { + self.expressions = expressions + self.ignoreAccents = ignoreAccents ?? FullTextIndexConfiguration.defaultIgnoreAccents + self.language = language } // MARK: Internal - - private let impl: CBLFullTextIndexConfiguration func toImpl() -> CBLIndexConfiguration { - return impl + return CBLFullTextIndexConfiguration(expression: expressions, ignoreAccents: ignoreAccents, language: language) } } -public class ValueIndexConfiguration: IndexConfiguration, IndexConfigConvertable { - +/// Configuration for creating value indexes. +public struct ValueIndexConfiguration: IndexConfiguration, IndexConfigConvertable { /// Gets the expressions to use to create the index. - public var expressions: [String] { - return self.impl.expressions - } + public let expressions: [String] /// Constructor for creating a value index by using an array of N1QL expression strings. - public init(_ expressions: [String]) { - self.impl = CBLValueIndexConfiguration(expression: expressions) + public init(_ expressions: [String]) { + self.expressions = expressions } // MARK: Internal - private let impl: CBLValueIndexConfiguration - func toImpl() -> CBLIndexConfiguration { - return self.impl + return CBLValueIndexConfiguration(expression: expressions) } } @@ -88,12 +75,10 @@ protocol IndexConfigConvertable { } extension IndexConfiguration { - func toImpl() -> CBLIndexConfiguration { if let index = self as? IndexConfigConvertable { return index.toImpl() } - - fatalError("Unsupported index.") + fatalError("Unsupported Index") } }