Skip to content

Commit

Permalink
fix: move score property into ParseQueryScorable (#319)
Browse files Browse the repository at this point in the history
* fix: move score property into ParseQueryScorable

* add change log

* disable pointer thread test on Linux
  • Loading branch information
cbaker6 committed Jan 17, 2022
1 parent 08882d0 commit 3c3a6e8
Show file tree
Hide file tree
Showing 84 changed files with 56 additions and 160 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

### main

[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/3.1.1...main)
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/3.1.2...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 3.1.2
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/3.1.1...3.1.2)

__Fixes__
- Allowing building of the Swift SDK for Swift 5.5.0 and 5.5.1 re-enabling builds for Xcode 13.0 and 13.1. Note that async/await functionality is only available for Swift 5.5.2+ and Xcode 13.2+ ([#320](https://github.com/parse-community/Parse-Swift/pull/320)), thanks to [Corey Baker](https://github.com/cbaker6).
- Move the var score: Double? to a protocol named ParseQueryScorable. When developers want to sort by score using a matchesText QueryConstraint, they just conform their ParseObject's to ParseQueryScorable ([#319](https://github.com/parse-community/Parse-Swift/pull/319)), thanks to [Corey Baker](https://github.com/cbaker6).

### 3.1.1
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/3.1.0...3.1.1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct GameScore: ParseObject, ParseObjectMutable {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand All @@ -61,7 +60,6 @@ struct GameData: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var polygon: ParsePolygon?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct User: ParseUser {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: These are required by `ParseUser`.
var username: String?
Expand All @@ -39,7 +38,6 @@ struct Role<RoleUser: ParseUser>: ParseRole {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Provided by Role.
var name: String
Expand All @@ -56,7 +54,6 @@ struct GameScore: ParseObject, ParseObjectMutable {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int? = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct GameScore: ParseObject, ParseObjectMutable {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct User: ParseUser, ParseObjectMutable {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: These are required by `ParseUser`.
var username: String?
Expand Down Expand Up @@ -53,7 +52,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int? = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties
var points: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct Installation: ParseInstallation {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: These are required by `ParseInstallation`.
var installationId: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?
var location: ParseGeoPoint?

//: Your own properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ PlaygroundPage.current.needsIndefiniteExecution = true
initializeParse()

//: Create your own value typed `ParseObject`.
struct Book: ParseObject {
struct Book: ParseObject, ParseQueryScorable {
//: These are required by ParseObject
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?
var relatedBook: Pointer<Book>?

//: Your own properties.
var title: String?
var relatedBook: Pointer<Book>?
}

//: It's recommended to place custom initializers in an extension
Expand All @@ -42,7 +42,6 @@ struct Author: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ struct GameScore: ParseObject {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

//: Your own properties.
var points: Int = 0
Expand Down
10 changes: 10 additions & 0 deletions ParseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@
70A2D86B25B3ADB6001BEB7D /* ParseAnonymousTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A2D86A25B3ADB6001BEB7D /* ParseAnonymousTests.swift */; };
70A2D86C25B3ADB6001BEB7D /* ParseAnonymousTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A2D86A25B3ADB6001BEB7D /* ParseAnonymousTests.swift */; };
70A2D86D25B3ADB6001BEB7D /* ParseAnonymousTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A2D86A25B3ADB6001BEB7D /* ParseAnonymousTests.swift */; };
70A98D822794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A98D812794AB3C009B58F2 /* ParseQueryScorable.swift */; };
70A98D832794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A98D812794AB3C009B58F2 /* ParseQueryScorable.swift */; };
70A98D842794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A98D812794AB3C009B58F2 /* ParseQueryScorable.swift */; };
70A98D852794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70A98D812794AB3C009B58F2 /* ParseQueryScorable.swift */; };
70B4E0BC2762F1D5004C9757 /* QueryConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B4E0BB2762F1D5004C9757 /* QueryConstraint.swift */; };
70B4E0BD2762F1D5004C9757 /* QueryConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B4E0BB2762F1D5004C9757 /* QueryConstraint.swift */; };
70B4E0BE2762F1D5004C9757 /* QueryConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B4E0BB2762F1D5004C9757 /* QueryConstraint.swift */; };
Expand Down Expand Up @@ -968,6 +972,7 @@
709B98342556EC7400507778 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
70A2D81E25B36A7D001BEB7D /* ParseAuthenticationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseAuthenticationTests.swift; sourceTree = "<group>"; };
70A2D86A25B3ADB6001BEB7D /* ParseAnonymousTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseAnonymousTests.swift; sourceTree = "<group>"; };
70A98D812794AB3C009B58F2 /* ParseQueryScorable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseQueryScorable.swift; sourceTree = "<group>"; };
70B4E0BB2762F1D5004C9757 /* QueryConstraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryConstraint.swift; sourceTree = "<group>"; };
70B4E0C02762F313004C9757 /* QueryWhere.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueryWhere.swift; sourceTree = "<group>"; };
70BC0B32251903D1001556DB /* ParseGeoPointTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseGeoPointTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1382,6 +1387,7 @@
700396E925A3892D0052CB31 /* LiveQuerySocketDelegate.swift */,
700396F725A394AE0052CB31 /* ParseLiveQueryDelegate.swift */,
700395D025A147BE0052CB31 /* QuerySubscribable.swift */,
70A98D812794AB3C009B58F2 /* ParseQueryScorable.swift */,
);
path = Protocols;
sourceTree = "<group>";
Expand Down Expand Up @@ -2226,6 +2232,7 @@
70510AAC259EE25E00FEA700 /* LiveQuerySocket.swift in Sources */,
70C167AF27304EE4009F4E30 /* Pointer+combine.swift in Sources */,
7044C19125C4F5B60011F6E7 /* ParseFile+combine.swift in Sources */,
70A98D822794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */,
70F79A192639CE6F00731C46 /* ParseHealth.swift in Sources */,
7044C19F25C4FA870011F6E7 /* ParseOperation+combine.swift in Sources */,
F97B461E24D9C6F200F4A88B /* ParseStorage.swift in Sources */,
Expand Down Expand Up @@ -2459,6 +2466,7 @@
7044C19225C4F5B60011F6E7 /* ParseFile+combine.swift in Sources */,
70F79A1A2639CE6F00731C46 /* ParseHealth.swift in Sources */,
7044C1A025C4FA870011F6E7 /* ParseOperation+combine.swift in Sources */,
70A98D832794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */,
F97B461F24D9C6F200F4A88B /* ParseStorage.swift in Sources */,
7044C1AE25C4FC080011F6E7 /* Query+combine.swift in Sources */,
F97B45D324D9C6F200F4A88B /* AnyDecodable.swift in Sources */,
Expand Down Expand Up @@ -2795,6 +2803,7 @@
70C167B227304EE4009F4E30 /* Pointer+combine.swift in Sources */,
7044C19425C4F5B60011F6E7 /* ParseFile+combine.swift in Sources */,
70F79A1C2639CE6F00731C46 /* ParseHealth.swift in Sources */,
70A98D852794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */,
7044C1A225C4FA870011F6E7 /* ParseOperation+combine.swift in Sources */,
F97B465124D9C78C00F4A88B /* Add.swift in Sources */,
7044C1B025C4FC080011F6E7 /* Query+combine.swift in Sources */,
Expand Down Expand Up @@ -2934,6 +2943,7 @@
70C167B127304EE4009F4E30 /* Pointer+combine.swift in Sources */,
7044C19325C4F5B60011F6E7 /* ParseFile+combine.swift in Sources */,
70F79A1B2639CE6F00731C46 /* ParseHealth.swift in Sources */,
70A98D842794AB3C009B58F2 /* ParseQueryScorable.swift in Sources */,
7044C1A125C4FA870011F6E7 /* ParseOperation+combine.swift in Sources */,
F97B465024D9C78B00F4A88B /* Add.swift in Sources */,
7044C1AF25C4FC080011F6E7 /* Query+combine.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/parse-community/Parse-Swift", from: "3.0.0"),
.package(url: "https://github.com/parse-community/Parse-Swift", from: "3.1.2"),
]
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ internal struct BaseParseInstallation: ParseInstallation {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?

static func createNewInstallationIfNeeded() {
guard let installationId = Self.currentContainer.installationId,
Expand Down
1 change: 0 additions & 1 deletion Sources/ParseSwift/InternalObjects/BaseParseUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ internal struct BaseParseUser: ParseUser {
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?
}
22 changes: 22 additions & 0 deletions Sources/ParseSwift/LiveQuery/Protocols/ParseQueryScorable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ParseQueryScorable.swift
// ParseSwift
//
// Created by Corey Baker on 1/16/22.
// Copyright © 2022 Parse Community. All rights reserved.
//

import Foundation

/**
Conform to this protocol to add the required properties to your `ParseObject`
for using `QueryConstraint.matchesText()` and `Query.sortByTextScore()`.
- note: In order to sort you must use `Query.sortByTextScore()`.
To retrieve the weight/rank, access the "score" property of your `ParseObject`.
*/
public protocol ParseQueryScorable {
/**
The weight/rank of a `QueryConstraint.matchesText()`.
*/
var score: Double? { get }
}
9 changes: 1 addition & 8 deletions Sources/ParseSwift/Objects/ParseObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import Foundation
create methods to check the respective properties on the client-side before saving objects. See
[here](https://github.com/parse-community/Parse-Swift/issues/157#issuecomment-858671025)
for more information.
- important: The property, "score," is a Parse Server designated keyword and you should avoid naming any of
your `ParseObject` properties "score". Doing so may result in decoding issues.
- warning: If you plan to use "reference types" (classes), you are using at your risk as this SDK is not designed
for reference types and may have unexpected behavior when it comes to threading. You will also need to implement
your own `==` method to conform to `Equatable` along with with the `hash` method to conform to `Hashable`.
Expand All @@ -46,12 +44,7 @@ public protocol ParseObject: Objectable,
Identifiable,
Hashable,
CustomDebugStringConvertible,
CustomStringConvertible {
/**
The weight/rank of a `QueryConstraint.matchesText()`.
*/
var score: Double? { get }
}
CustomStringConvertible { }

// MARK: Default Implementations
public extension ParseObject {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "3.1.1"
static let version = "3.1.2"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
2 changes: 0 additions & 2 deletions Sources/ParseSwift/Protocols/ParseObjectMutable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Foundation
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?
//: These are required by `ParseUser`.
var username: String?
Expand Down Expand Up @@ -58,7 +57,6 @@ import Foundation
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var score: Double?
//: Your own properties.
var points: Int = 0
Expand Down
2 changes: 2 additions & 0 deletions Sources/ParseSwift/Types/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
/**
Method to sort the full text search by text score.
- parameter value: String or Object of index that should be used when executing query.
- note: Your `ParseObject` should conform to `ParseQueryScorable` to retrieve
the weight/rank via the "score" property of your `ParseObject`.
*/
public func sortByTextScore() -> Query<T> {
var mutableQuery = self
Expand Down
6 changes: 4 additions & 2 deletions Sources/ParseSwift/Types/QueryConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ public func polygonContains(key: String, point: ParseGeoPoint) -> QueryConstrain
- parameter text: The substring that the value must contain.
- returns: The resulting `QueryConstraint`.
- note: In order to sort you must use `Query.sortByTextScore()`.
To retrieve the weight/rank, access the "score" property of your `ParseObject`.
Your `ParseObject` should conform to `ParseQueryScorable` to retrieve
the weight/rank via the "score" property of your `ParseObject`.
- warning: This may be slow for large datasets. Requires Parse Server > 2.5.0.
*/
public func matchesText(key: String, text: String) -> QueryConstraint {
Expand Down Expand Up @@ -661,7 +662,8 @@ public enum ParseTextOption: String {
The key is of type `TextOption` and must have a respective value.
- returns: The resulting `QueryConstraint`.
- note: In order to sort you must use `Query.sortByTextScore()`.
To retrieve the weight/rank, access the "score" property of your `ParseObject`.
Your `ParseObject` should conform to `ParseQueryScorable` to retrieve
the weight/rank via the "score" property of your `ParseObject`.
- warning: This may be slow for large datasets. Requires Parse Server > 2.5.0.
*/
public func matchesText(key: String,
Expand Down
Loading

0 comments on commit 3c3a6e8

Please sign in to comment.