Repository Public
1// SP Notes Core2// File: Sources/SPNotesAPI/NotesAPI+Search.swift3// Description: The search routes beside `search(_:)`: near-duplicate pages, the state of the index and its rebuild.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation89extension NotesAPI {10 /// `GET /api/search/duplicates[?threshold=]` — pairs of pages with near-identical passages (needs embeddings;11 /// reads the index only, no provider call). Server default threshold 0.93.12 public func duplicatePages(threshold: Double? = nil) async throws -> [DuplicatePair] {13 try await client.decode([DuplicatePair].self, .get("/api/search/duplicates", query: Self.item("threshold", threshold.map { String($0) })))14 }1516 /// `GET /api/search/index-state` — counters of the index and what it is missing.17 public func searchIndexState() async throws -> SearchIndexState {18 try await client.decode(SearchIndexState.self, .get("/api/search/index-state"))19 }2021 private struct ReindexBody: Encodable { var scope: String }2223 /// `POST /api/search/index-state` `{ scope }` — queues index jobs. **Indexing embeds text with the paid embedding24 /// provider when one is configured.**25 /// - Parameter pendingOnly: `true` = only what is missing or failed (`pending`); `false` = the whole index (`all`).26 public func reindexSearch(pendingOnly: Bool = true) async throws -> SearchReindexResult {27 try await client.decode(SearchReindexResult.self, .json(.post, "/api/search/index-state", body: ReindexBody(scope: pendingOnly ? "pending" : "all")))28 }29}30