Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Vrai-Prix iOS9// File : VraiPrix/Core/System/SpotlightIndex.swift10// Description : recherche Spotlight et reprise d'activité (Handoff). Les11// fiches consultées et les favoris deviennent trouvables sur12// l'appareil ; l'index ne quitte pas l'appareil. Ce qui est13// indexé est ce que le service a rendu : jamais un montant14// pour une propriété sans valeur.15// Module : VraiPrix16// Repository : https://git.spboucher.ai/vrai-prix-ios-v317// Project Website : https://www.vrai-prix.com18// Created : 2026-11-2819// Last Modified : 2026-11-2820//21// =============================================================================22// AUTHOR & PROFESSIONAL AFFILIATION23// =============================================================================24//25// Author : Simon-Pierre Boucher26// Position : Professor of Finance27// Institution : Université du Québec en Outaouais (UQO)28// Department : Département des sciences administratives29// Organization : SP Boucher30//31// Website : https://spboucher.ai32// Git : https://git.spboucher.ai33//34// =============================================================================35// OFFICIAL CONTACT DIRECTORY36// =============================================================================37//38// General : info@spboucher.ai39// Professional : contact@spboucher.ai40// Direct : simon@spboucher.ai41// Research : research@spboucher.ai42// Development : dev@spboucher.ai43// Support : support@spboucher.ai44// Security/Admin : admin@spboucher.ai45// Notifications : notifications@spboucher.ai46//47// Preferred Contact: support@spboucher.ai48//49// =============================================================================50// COPYRIGHT & INTELLECTUAL PROPERTY51// =============================================================================52//53// Copyright (c) 202654// Simon-Pierre Boucher55//56// All rights reserved where applicable.57//58// This file is governed by the applicable project license,59// copyright notices, institutional agreements and relevant law.60//61// Unless expressly authorized by the applicable license or62// rights holder, copying, redistribution, sublicensing,63// publication and commercial exploitation are not permitted.64//65// Existing third-party rights and notices remain unaffected.66//67// =============================================================================68// CONFIDENTIALITY & SECURITY69// =============================================================================70//71// Classification : Public72// Distribution : Public repository; use is governed by the project license73// Security Contact : admin@spboucher.ai74//75// Access to this source does not independently grant permission76// to redistribute or disclose confidential materials.77//78// Do not embed credentials, private keys, access tokens,79// certificates or confidential personal information.80//81// =============================================================================82// LICENSE & MAINTENANCE83// =============================================================================84//85// License : None specified (no license file in this repository)86// Maintainer : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import CoreSpotlight94import Foundation95import UniformTypeIdentifiers9697enum SpotlightIndex {98 static let domain = "com.spboucher.vraiprix.v2.fiches"99 static let favoritesDomain = "com.spboucher.vraiprix.v2.favoris"100101 /// Identifiant Spotlight d'une propriété mémorisée : son chemin dans l'app (`propriete/<id>`, `a-vendre/<uid>`).102 static func identifier(_ p: SavedProperty) -> String { (p.kind == .unit ? "propriete/" : "a-vendre/") + p.ref }103104 static func describe(_ p: SavedProperty) -> String {105 var parts: [String] = []106 if let v = p.valueBlock {107 if let a = ValueFmt.amount(v) { parts.append((v.status == .ordre ? "Ordre de grandeur " : "Valeur estimée ") + a) } else { parts.append("Aucune valeur") }108 } else if let v = p.value {109 parts.append("Valeur estimée " + Fmt.money(v))110 }111 if p.kind == .listing, let price = p.price { parts.append("prix demandé " + Fmt.money(price)) }112 if !p.subtitle.isEmpty { parts.append(p.subtitle) }113 return parts.joined(separator: " · ")114 }115116 static func item(_ p: SavedProperty, favorite: Bool) -> CSSearchableItem {117 let a = CSSearchableItemAttributeSet(contentType: .content)118 a.title = p.title119 a.contentDescription = describe(p)120 a.keywords = ["Vrai-Prix", "valeur", "propriété", p.kind == .listing ? "à vendre" : "estimation"] + p.subtitle.components(separatedBy: " · ")121 a.contentURL = APIClient.site.appending(path: p.kind == .unit ? "estimation" : "a-vendre").appending(path: p.ref)122 let item = CSSearchableItem(uniqueIdentifier: identifier(p), domainIdentifier: favorite ? favoritesDomain : domain, attributeSet: a)123 // une fiche consultée reste trouvable 30 jours ; un favori, tant qu'il l'est124 item.expirationDate = favorite ? .distantFuture : Date().addingTimeInterval(30 * 86400)125 return item126 }127128 static func index(_ p: SavedProperty, favorite: Bool = false) {129 guard CSSearchableIndex.isIndexingAvailable(), UserDefaults.standard.object(forKey: "VPInMemory") == nil else { return }130 CSSearchableIndex.default().indexSearchableItems([item(p, favorite: favorite)]) { _ in }131 }132133 static func remove(_ p: SavedProperty) {134 CSSearchableIndex.default().deleteSearchableItems(withIdentifiers: [identifier(p)]) { _ in }135 }136137 static func removeAll() {138 CSSearchableIndex.default().deleteSearchableItems(withDomainIdentifiers: [domain, favoritesDomain]) { _ in }139 }140141 /// Adresse `vraiprix://…` d'un résultat Spotlight touché.142 static func url(from activity: NSUserActivity) -> URL? {143 guard activity.activityType == CSSearchableItemActionType,144 let id = activity.userInfo?[CSSearchableItemActivityIdentifier] as? String else { return nil }145 return URL(string: "vraiprix://" + (id.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? id))146 }147}148149/// Reprise d'une fiche sur un autre appareil : l'activité porte l'adresse publique de la page.150enum Handoff {151 static let propertyActivity = "com.spboucher.vraiprix.v2.propriete"152 static let listingActivity = "com.spboucher.vraiprix.v2.inscription"153154 static func fill(_ a: NSUserActivity, title: String, path: String) {155 a.title = title156 a.isEligibleForHandoff = true157 a.isEligibleForSearch = false158 a.webpageURL = path.split(separator: "/").reduce(APIClient.site) { $0.appending(path: String($1)) }159 }160}161