Skip to content

Commit

Permalink
Merge pull request #36 from phiHero/master
Browse files Browse the repository at this point in the history
Update synonym schema, add operation clear cache endpoint
  • Loading branch information
jasonbosco authored Aug 27, 2024
2 parents 126815b + d345353 commit 58e996a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
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)
}
}
}

0 comments on commit 58e996a

Please sign in to comment.