Skip to content
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
17 changes: 17 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1580,3 +1580,20 @@ swap_indexes_1: |-
("indexA", "indexB"),
("indexX", "indexY")
])
create_snapshot_1: |-
let task = try await self.client.createSnapshot()
get_proximity_precision_settings_1: |-
let precisionValue = try await self.client.index("books").getProximityPrecision()
update_proximity_precision_settings_1: |-
let task = try await self.client.index("books").updateProximityPrecision(.byWord)
reset_proximity_precision_settings_1: |-
let task = try await self.client.index("books").resetProximityPrecision()
get_search_cutoff_1: |-
let precisionValue = try await self.client.index("books").getSearchCutoffMs()
update_search_cutoff_1: |-
let task = try await self.client.index("books").updateSearchCutoffMs(150)
reset_search_cutoff_1: |-
let task = try await self.client.index("books").resetSearchCutoffMs()
search_parameter_guide_show_ranking_score_details_1: |-
let searchParameters = SearchParameters(query: "dragon", showRankingScoreDetails: true)
let movies: Searchable<Movie> = try await client.index("movies").search(searchParameters)
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
os: ["macos-latest", "ubuntu-20.04"]
env:
GITHUB_PAT: ${{ secrets.MEILIBOT_PAT_REPO }}
GITHUB_PAT: ${{ secrets.MEILI_BOT_GH_PAT }}
steps:
- uses: actions/checkout@v4
- name: Download the latest stable version of Meilisearch
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ iOSInjectionProject/

.swiftpm
.vscode/

# MeiliSearch

meilisearch
data.ms
dumps/*.dump
snapshots/*.snapshot
4 changes: 2 additions & 2 deletions MeiliSearch.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Pod::Spec.new do |s|
s.source_files = 'Sources/**/*.{h,m,swift}'

s.swift_versions = ['5.2']
s.ios.deployment_target = '10.0'
s.osx.deployment_target = '10.10'
s.ios.deployment_target = '12.0'
s.osx.deployment_target = '10.13'

end
11 changes: 11 additions & 0 deletions Sources/MeiliSearch/Async/Client+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,15 @@ extension MeiliSearch {
}
}
}

/**
See `createSnapshot(_:)`
*/
public func createSnapshot() async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.createSnapshot { result in
continuation.resume(with: result)
}
}
}
}
66 changes: 66 additions & 0 deletions Sources/MeiliSearch/Async/Indexes+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,72 @@ extension Indexes {
}
}

/**
See `getProximityPrecision(_:)`
*/
public func getProximityPrecision() async throws -> ProximityPrecision {
try await withCheckedThrowingContinuation { continuation in
self.getProximityPrecision { result in
continuation.resume(with: result)
}
}
}

/**
See `updateProximityPrecision(_:_:)`
*/
public func updateProximityPrecision(_ proximityPrecision: ProximityPrecision) async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.updateProximityPrecision(proximityPrecision) { result in
continuation.resume(with: result)
}
}
}

/**
See `resetProximityPrecision(_:)`
*/
public func resetProximityPrecision() async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.resetProximityPrecision { result in
continuation.resume(with: result)
}
}
}

/**
See `getSearchCutoffMs(_:)`
*/
public func getSearchCutoffMs() async throws -> Int? {
try await withCheckedThrowingContinuation { continuation in
self.getSearchCutoffMs { result in
continuation.resume(with: result)
}
}
}

/**
See `updateSearchCutoffMs(_:_:)`
*/
public func updateSearchCutoffMs(_ newValue: Int) async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.updateSearchCutoffMs(newValue) { result in
continuation.resume(with: result)
}
}
}

/**
See `resetSearchCutoffMs(_:)`
*/
public func resetSearchCutoffMs() async throws -> TaskInfo {
try await withCheckedThrowingContinuation { continuation in
self.resetSearchCutoffMs { result in
continuation.resume(with: result)
}
}
}

/**
See `stats(_:)`
*/
Expand Down
13 changes: 13 additions & 0 deletions Sources/MeiliSearch/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public struct MeiliSearch {
private let stats: Stats
private let system: System
private let dumps: Dumps
private let snapshots: Snapshots
private let tasks: Tasks

// MARK: Initializers
Expand All @@ -42,6 +43,7 @@ public struct MeiliSearch {
self.stats = Stats(self.request)
self.system = System(self.request)
self.dumps = Dumps(self.request)
self.snapshots = Snapshots(self.request)
self.tasks = Tasks(self.request)
}

Expand Down Expand Up @@ -381,4 +383,15 @@ public struct MeiliSearch {
public func createDump(_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.dumps.create(completion)
}

/**
Triggers the snapshot creation process.

- parameter completion: The completion closure is used to notify when the server
completes the query request, it returns a `Result` object that contains `TaskInfo` value.
If the request was successful or `Error` if a failure occurred.
*/
public func createSnapshot(_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.snapshots.create(completion)
}
}
80 changes: 80 additions & 0 deletions Sources/MeiliSearch/Indexes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,86 @@ public struct Indexes {
self.settings.resetTypoTolerance(self.uid, completion)
}

// MARK: Proximity Precision

/**
Get the proximity precision value.

- parameter completion: The completion closure is used to notify when the server
completes the query request, it returns a `Result` object that contains a `TypoToleranceResult`
value if the request was successful, or `Error` if a failure occurred.
*/
public func getProximityPrecision(
_ completion: @escaping (Result<ProximityPrecision, Swift.Error>) -> Void) {
self.settings.getSetting(uid: uid, key: "proximity-precision", completion: completion)
}

/**
Update the proximity precision value.

- parameter proximityPrecision: The new value.
- parameter completion: The completion closure is used to notify when the server
completes the query request, it returns a `Result` object that contains `TaskInfo`
value if the request was successful, or `Error` if a failure occurred.
*/
public func updateProximityPrecision(
_ proximityPrecision: ProximityPrecision,
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.settings.updateSetting(uid: uid, key: "proximity-precision", data: proximityPrecision.rawValue, completion: completion)
}

/**
Reset the proximity precision value.

- parameter completion: The completion closure is used to notify when the server
completes the query request, it returns a `Result` object that contains `TaskInfo`
value if the request was successful, or `Error` if a failure occurred.
*/
public func resetProximityPrecision(
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.settings.resetSetting(uid: uid, key: "proximity-precision", completion: completion)
}

// MARK: Search Cutoff

/**
Get the search cut-off value.

- parameter completion: The completion closure is used to notify when the server
completes the query request, it returns a `Result` object that contains a `TypoToleranceResult`
value if the request was successful, or `Error` if a failure occurred.
*/
public func getSearchCutoffMs(
_ completion: @escaping (Result<Int?, Swift.Error>) -> Void) {
self.settings.getSetting(uid: uid, key: "search-cutoff-ms", completion: completion)
}

/**
Update the search cut-off value.

- parameter newValue: The new cut-off in milliseconds.
- parameter completion: The completion closure is used to notify when the server
completes the query request, it returns a `Result` object that contains `TaskInfo`
value if the request was successful, or `Error` if a failure occurred.
*/
public func updateSearchCutoffMs(
_ newValue: Int,
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.settings.updateSetting(uid: uid, key: "search-cutoff-ms", data: newValue, completion: completion)
}

/**
Reset the search cut-off value.

- parameter completion: The completion closure is used to notify when the server
completes the query request, it returns a `Result` object that contains `TaskInfo`
value if the request was successful, or `Error` if a failure occurred.
*/
public func resetSearchCutoffMs(
_ completion: @escaping (Result<TaskInfo, Swift.Error>) -> Void) {
self.settings.resetSetting(uid: uid, key: "search-cutoff-ms", completion: completion)
}

// MARK: Stats

/**
Expand Down
6 changes: 6 additions & 0 deletions Sources/MeiliSearch/Model/ProximityPrecision.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Foundation

public enum ProximityPrecision: String, Codable {
case byWord
case byAttribute
}
9 changes: 8 additions & 1 deletion Sources/MeiliSearch/Model/SearchParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public struct SearchParameters: Codable, Equatable {
/// Whether to return the search ranking score or not.
public let showRankingScore: Bool?

/// Whether to return the ranking score details or not.
public let showRankingScoreDetails: Bool?

// MARK: Initializers

public init(
Expand All @@ -85,7 +88,9 @@ public struct SearchParameters: Codable, Equatable {
sort: [String]? = nil,
facets: [String]? = nil,
showMatchesPosition: Bool? = nil,
showRankingScore: Bool? = nil) {
showRankingScore: Bool? = nil,
showRankingScoreDetails: Bool? = nil
) {
self.query = query
self.offset = offset
self.limit = limit
Expand All @@ -104,6 +109,7 @@ public struct SearchParameters: Codable, Equatable {
self.facets = facets
self.showMatchesPosition = showMatchesPosition
self.showRankingScore = showRankingScore
self.showRankingScoreDetails = showRankingScoreDetails
}

// MARK: Query Initializers
Expand Down Expand Up @@ -139,5 +145,6 @@ public struct SearchParameters: Codable, Equatable {
case hitsPerPage
case page
case showRankingScore
case showRankingScoreDetails
}
}
4 changes: 4 additions & 0 deletions Sources/MeiliSearch/Model/SearchResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Searchable<T>: Equatable, Codable where T: Codable, T: Equatable {
public struct SearchHit<T>: Equatable, Codable where T: Codable, T: Equatable {
public let document: T
public internal(set) var rankingScore: Double?
public internal(set) var rankingScoreDetails: [String: SearchScoreRankingDetails]?

/// Dynamic member lookup is used to allow easy access to instance members of the hit result, maintaining a level of backwards compatibility.
public subscript<V>(dynamicMember keyPath: KeyPath<T, V>) -> V {
Expand All @@ -48,12 +49,14 @@ public struct SearchHit<T>: Equatable, Codable where T: Codable, T: Equatable {

enum CodingKeys: String, CodingKey {
case rankingScore = "_rankingScore"
case rankingScoreDetails = "_rankingScoreDetails"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.document = try T(from: decoder)
self.rankingScore = try container.decodeIfPresent(Double.self, forKey: .rankingScore)
self.rankingScoreDetails = try container.decodeIfPresent([String: SearchScoreRankingDetails].self, forKey: .rankingScoreDetails)
}

public func encode(to encoder: Encoder) throws {
Expand All @@ -62,6 +65,7 @@ public struct SearchHit<T>: Equatable, Codable where T: Codable, T: Equatable {

var containerTwo = encoder.container(keyedBy: CodingKeys.self)
try containerTwo.encodeIfPresent(rankingScore, forKey: .rankingScore)
try containerTwo.encodeIfPresent(rankingScoreDetails, forKey: .rankingScoreDetails)
}
}

Expand Down
18 changes: 18 additions & 0 deletions Sources/MeiliSearch/Model/SearchScoreRankingDetails.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

public struct SearchScoreRankingDetails: Codable, Equatable {
public enum MatchType: String, Codable {
case exactMatch, matchesStart, noExactMatch
}

public let order: Int
public let score: Double?
public let maxTypoCount: Int?
public let typoCount: Int?
public let maxMatchingWords: Int?
public let matchingWords: Int?
public let value: String?
public let matchType: MatchType?
public let queryWordDistanceScore: Double?
public let attributeRankingOrderScore: Double?
}
12 changes: 11 additions & 1 deletion Sources/MeiliSearch/Model/Setting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public struct Setting: Codable, Equatable {
/// Settings for typo tolerance
public let typoTolerance: TypoTolerance?

/// Precision level when calculating the proximity ranking rule
public let proximityPrecision: ProximityPrecision?

/// Maximum duration of a search query
public let searchCutoffMs: Int?

/// List of tokens that will be considered as word separators by Meilisearch.
public let separatorTokens: [String]?

Expand Down Expand Up @@ -63,7 +69,9 @@ public struct Setting: Codable, Equatable {
nonSeparatorTokens: [String]? = nil,
dictionary: [String]? = nil,
pagination: Pagination? = nil,
typoTolerance: TypoTolerance? = nil
typoTolerance: TypoTolerance? = nil,
proximityPrecision: ProximityPrecision? = nil,
searchCutoffMs: Int? = nil
) {
self.rankingRules = rankingRules
self.searchableAttributes = searchableAttributes
Expand All @@ -78,5 +86,7 @@ public struct Setting: Codable, Equatable {
self.dictionary = dictionary
self.pagination = pagination
self.typoTolerance = typoTolerance
self.proximityPrecision = proximityPrecision
self.searchCutoffMs = searchCutoffMs
}
}
6 changes: 6 additions & 0 deletions Sources/MeiliSearch/Model/SettingResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ public struct SettingResult: Codable, Equatable {

/// Settings for typo tolerance
public let typoTolerance: TypoToleranceResult

/// Precision level when calculating the proximity ranking rule
public let proximityPrecision: ProximityPrecision

/// Maximum duration of a search query
public let searchCutoffMs: Int?
}
Loading
Loading