@@ -309,11 +309,49 @@ public class Query : NSObject, NSCopying {
309309 set { self [ " allowTyposOnNumericTokens " ] = Query . buildBool ( newValue) }
310310 }
311311
312- /// If set to true, simple plural forms won’t be considered as typos (for example car/cars will be considered as
313- /// equal).
314- public var ignorePlurals : Bool ? {
315- get { return Query . parseBool ( self [ " ignorePlurals " ] ) }
316- set { self [ " ignorePlurals " ] = Query . buildBool ( newValue) }
312+ /// Applicable values for the `ignorePlurals` parameter.
313+ public enum IgnorePlurals : Equatable {
314+ /// Enable/disable plurals on all supported languages.
315+ case all( Bool )
316+ /// Enable plurals on a specific set of languages, identified by their ISO code.
317+ case selected( [ String ] )
318+
319+ // NOTE: Associated values disable automatic conformance to `Equatable`, so we have to implement it ourselves.
320+ static public func == ( lhs: IgnorePlurals , rhs: IgnorePlurals ) -> Bool {
321+ switch ( lhs, rhs) {
322+ case ( let . all( lhsValue) , let . all( rhsValue) ) : return lhsValue == rhsValue
323+ case ( let . selected( lhsValue) , let . selected( rhsValue) ) : return lhsValue == rhsValue
324+ default : return false
325+ }
326+ }
327+ }
328+
329+ /// Consider singular and plurals forms alike to be a match without typo. For example, "car" and "cars", or "foot"
330+ /// and "feet", will be considered equivalent. This parameter can be:
331+ ///
332+ /// You may enable this option for all languages at once (`.all`) or for a specific subset (`.selected`).
333+ ///
334+ public var ignorePlurals : IgnorePlurals ? {
335+ get {
336+ let stringValue = self [ " ignorePlurals " ]
337+ if let boolValue = Query . parseBool ( stringValue) {
338+ return . all( boolValue)
339+ } else if let arrayValue = Query . parseStringArray ( stringValue) {
340+ return . selected( arrayValue)
341+ } else {
342+ return nil
343+ }
344+ }
345+ set {
346+ if let newValue = newValue {
347+ switch newValue {
348+ case let . all( boolValue) : self [ " ignorePlurals " ] = Query . buildBool ( boolValue)
349+ case let . selected( arrayValue) : self [ " ignorePlurals " ] = Query . buildStringArray ( arrayValue)
350+ }
351+ } else {
352+ self [ " ignorePlurals " ] = nil
353+ }
354+ }
317355 }
318356
319357 /// List of attributes you want to use for textual search (must be a subset of the `searchableAttributes` index setting).
@@ -1066,9 +1104,28 @@ public class Query : NSObject, NSCopying {
10661104 }
10671105
10681106 @objc ( ignorePlurals)
1069- public var z_objc_ignorePlurals : NSNumber ? {
1070- get { return Query . toNumber ( self . ignorePlurals) }
1071- set { self . ignorePlurals = newValue? . boolValue }
1107+ public var z_objc_ignorePlurals : Any ? {
1108+ get {
1109+ if let value = ignorePlurals {
1110+ switch value {
1111+ case let . all( boolValue) : return NSNumber ( value: boolValue)
1112+ case let . selected( arrayValue) : return arrayValue
1113+ }
1114+ } else {
1115+ return nil
1116+ }
1117+ }
1118+ set {
1119+ if let boolValue = newValue as? Bool {
1120+ ignorePlurals = . all( boolValue)
1121+ } else if let numberValue = newValue as? NSNumber {
1122+ ignorePlurals = . all( numberValue. boolValue)
1123+ } else if let arrayValue = newValue as? [ String ] {
1124+ ignorePlurals = . selected( arrayValue)
1125+ } else {
1126+ ignorePlurals = nil
1127+ }
1128+ }
10721129 }
10731130
10741131 @objc ( advancedSyntax)
0 commit comments