Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update synonym schema, add operation clear cache endpoint #36

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Sources/Typesense/Models/SearchSynonym.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ public struct SearchSynonym: Codable {
/** Array of words that should be considered as synonyms. */
public var synonyms: [String]
public var _id: String
/** Locale for the synonym, leave blank to use the standard tokenizer. */
public var locale: String?
/** By default, special characters are dropped from synonyms. Use this attribute to specify which special characters should be indexed as is. */
public var symbolsToIndex: [String]?

public init(root: String? = nil, synonyms: [String], _id: String) {
public init(root: String? = nil, synonyms: [String], _id: String, locale: String? = nil, symbolsToIndex: [String]? = nil) {
self.root = root
self.synonyms = synonyms
self._id = _id
self.locale = locale
self.symbolsToIndex = symbolsToIndex
}

public enum CodingKeys: String, CodingKey {
public enum CodingKeys: String, CodingKey {
case _id = "id"
case root
case synonyms
case _id = "id"
case locale
case symbolsToIndex = "symbols_to_index"
}

}
14 changes: 13 additions & 1 deletion Sources/Typesense/Models/SearchSynonymSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ public struct SearchSynonymSchema: Codable {
public var root: String?
/** Array of words that should be considered as synonyms. */
public var synonyms: [String]
/** Locale for the synonym, leave blank to use the standard tokenizer. */
public var locale: String?
/** By default, special characters are dropped from synonyms. Use this attribute to specify which special characters should be indexed as is. */
public var symbolsToIndex: [String]?

public init(root: String? = nil, synonyms: [String]) {
public init(root: String? = nil, synonyms: [String], locale: String? = nil, symbolsToIndex: [String]? = nil) {
self.root = root
self.synonyms = synonyms
self.locale = locale
self.symbolsToIndex = symbolsToIndex
}

public enum CodingKeys: String, CodingKey {
case root
case synonyms
case locale
case symbolsToIndex = "symbols_to_index"
}

}
9 changes: 9 additions & 0 deletions Sources/Typesense/Operations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ public struct Operations {
return (nil, nil)
}

public func clearCache() async throws -> (SuccessStatus?, URLResponse?) {
let (data, response) = try await apiCall.post(endPoint: "\(RESOURCEPATH)/cache/clear", body: Data())
if let result = data {
let success = try decoder.decode(SuccessStatus.self, from: result)
return (success, response)
}
return (nil, response)
}

}
14 changes: 14 additions & 0 deletions Tests/TypesenseTests/OperationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,18 @@ final class OperationTests: XCTestCase {
XCTAssertTrue(false)
}
}

func testOperationClearCache() async {
do {
let (data, _) = try await client.operations().clearCache()
guard let validData = data else {
throw DataError.dataNotFound
}
print(validData)
XCTAssertNotNil(validData.success)
} catch (let error) {
print(error.localizedDescription)
XCTAssertTrue(false)
}
}
}
Loading