1use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13#[doc(alias = "SKSearchRef")]
15#[repr(C)]
16pub struct SKSearch {
17 inner: [u8; 0],
18 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
19}
20
21cf_type!(
22 unsafe impl SKSearch {}
23);
24#[cfg(feature = "objc2")]
25cf_objc2_type!(
26 unsafe impl RefEncode<"__SKSearch"> for SKSearch {}
27);
28
29unsafe impl ConcreteType for SKSearch {
30 #[doc(alias = "SKSearchGetTypeID")]
31 #[inline]
32 fn type_id() -> CFTypeID {
33 extern "C-unwind" {
34 fn SKSearchGetTypeID() -> CFTypeID;
35 }
36 unsafe { SKSearchGetTypeID() }
37 }
38}
39
40pub type SKSearchOptions = u32;
42
43pub const kSKSearchOptionDefault: c_uint = 0;
45pub const kSKSearchOptionNoRelevanceScores: c_uint = 1 << 0;
47pub const kSKSearchOptionSpaceMeansOR: c_uint = 1 << 1;
49pub const kSKSearchOptionFindSimilar: c_uint = 1 << 2;
51
52impl SKSearch {
53 #[doc(alias = "SKSearchCreate")]
58 #[cfg(feature = "SKIndex")]
59 #[inline]
60 pub unsafe fn new(
61 in_index: Option<&SKIndex>,
62 in_query: Option<&CFString>,
63 in_search_options: SKSearchOptions,
64 ) -> Option<CFRetained<SKSearch>> {
65 extern "C-unwind" {
66 fn SKSearchCreate(
67 in_index: Option<&SKIndex>,
68 in_query: Option<&CFString>,
69 in_search_options: SKSearchOptions,
70 ) -> Option<NonNull<SKSearch>>;
71 }
72 let ret = unsafe { SKSearchCreate(in_index, in_query, in_search_options) };
73 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
74 }
75
76 #[doc(alias = "SKSearchCancel")]
77 #[inline]
78 pub unsafe fn cancel(&self) {
79 extern "C-unwind" {
80 fn SKSearchCancel(in_search: &SKSearch);
81 }
82 unsafe { SKSearchCancel(self) }
83 }
84
85 #[doc(alias = "SKSearchFindMatches")]
91 #[cfg(feature = "SKIndex")]
92 #[inline]
93 pub unsafe fn find_matches(
94 &self,
95 in_maximum_count: CFIndex,
96 out_document_i_ds_array: *mut SKDocumentID,
97 out_scores_array: *mut c_float,
98 maximum_time: CFTimeInterval,
99 out_found_count: *mut CFIndex,
100 ) -> bool {
101 extern "C-unwind" {
102 fn SKSearchFindMatches(
103 in_search: &SKSearch,
104 in_maximum_count: CFIndex,
105 out_document_i_ds_array: *mut SKDocumentID,
106 out_scores_array: *mut c_float,
107 maximum_time: CFTimeInterval,
108 out_found_count: *mut CFIndex,
109 ) -> Boolean;
110 }
111 let ret = unsafe {
112 SKSearchFindMatches(
113 self,
114 in_maximum_count,
115 out_document_i_ds_array,
116 out_scores_array,
117 maximum_time,
118 out_found_count,
119 )
120 };
121 ret != 0
122 }
123}
124
125#[cfg(feature = "SKIndex")]
126impl SKIndex {
127 #[doc(alias = "SKIndexCopyInfoForDocumentIDs")]
133 #[cfg(feature = "SKIndex")]
134 #[inline]
135 pub unsafe fn copy_info_for_document_ids(
136 &self,
137 in_count: CFIndex,
138 in_document_i_ds_array: *mut SKDocumentID,
139 out_names_array: *mut *const CFString,
140 out_parent_i_ds_array: *mut SKDocumentID,
141 ) {
142 extern "C-unwind" {
143 fn SKIndexCopyInfoForDocumentIDs(
144 in_index: &SKIndex,
145 in_count: CFIndex,
146 in_document_i_ds_array: *mut SKDocumentID,
147 out_names_array: *mut *const CFString,
148 out_parent_i_ds_array: *mut SKDocumentID,
149 );
150 }
151 unsafe {
152 SKIndexCopyInfoForDocumentIDs(
153 self,
154 in_count,
155 in_document_i_ds_array,
156 out_names_array,
157 out_parent_i_ds_array,
158 )
159 }
160 }
161
162 #[doc(alias = "SKIndexCopyDocumentRefsForDocumentIDs")]
167 #[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
168 #[inline]
169 pub unsafe fn copy_document_refs_for_document_ids(
170 &self,
171 in_count: CFIndex,
172 in_document_i_ds_array: *mut SKDocumentID,
173 out_document_refs_array: *mut *const SKDocument,
174 ) {
175 extern "C-unwind" {
176 fn SKIndexCopyDocumentRefsForDocumentIDs(
177 in_index: &SKIndex,
178 in_count: CFIndex,
179 in_document_i_ds_array: *mut SKDocumentID,
180 out_document_refs_array: *mut *const SKDocument,
181 );
182 }
183 unsafe {
184 SKIndexCopyDocumentRefsForDocumentIDs(
185 self,
186 in_count,
187 in_document_i_ds_array,
188 out_document_refs_array,
189 )
190 }
191 }
192
193 #[doc(alias = "SKIndexCopyDocumentURLsForDocumentIDs")]
198 #[cfg(feature = "SKIndex")]
199 #[inline]
200 pub unsafe fn copy_document_urls_for_document_ids(
201 &self,
202 in_count: CFIndex,
203 in_document_i_ds_array: *mut SKDocumentID,
204 out_document_ur_ls_array: *mut *const CFURL,
205 ) {
206 extern "C-unwind" {
207 fn SKIndexCopyDocumentURLsForDocumentIDs(
208 in_index: &SKIndex,
209 in_count: CFIndex,
210 in_document_i_ds_array: *mut SKDocumentID,
211 out_document_ur_ls_array: *mut *const CFURL,
212 );
213 }
214 unsafe {
215 SKIndexCopyDocumentURLsForDocumentIDs(
216 self,
217 in_count,
218 in_document_i_ds_array,
219 out_document_ur_ls_array,
220 )
221 }
222 }
223}
224
225#[doc(alias = "SKSearchGroupRef")]
227#[repr(C)]
228pub struct SKSearchGroup {
229 inner: [u8; 0],
230 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
231}
232
233cf_type!(
234 unsafe impl SKSearchGroup {}
235);
236#[cfg(feature = "objc2")]
237cf_objc2_type!(
238 unsafe impl RefEncode<"__SKSearchGroup"> for SKSearchGroup {}
239);
240
241unsafe impl ConcreteType for SKSearchGroup {
242 #[doc(alias = "SKSearchGroupGetTypeID")]
243 #[inline]
244 fn type_id() -> CFTypeID {
245 extern "C-unwind" {
246 fn SKSearchGroupGetTypeID() -> CFTypeID;
247 }
248 unsafe { SKSearchGroupGetTypeID() }
249 }
250}
251
252#[doc(alias = "SKSearchResultsRef")]
254#[repr(C)]
255pub struct SKSearchResults {
256 inner: [u8; 0],
257 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
258}
259
260cf_type!(
261 unsafe impl SKSearchResults {}
262);
263#[cfg(feature = "objc2")]
264cf_objc2_type!(
265 unsafe impl RefEncode<"__SKSearchResults"> for SKSearchResults {}
266);
267
268unsafe impl ConcreteType for SKSearchResults {
269 #[doc(alias = "SKSearchResultsGetTypeID")]
270 #[inline]
271 fn type_id() -> CFTypeID {
272 extern "C-unwind" {
273 fn SKSearchResultsGetTypeID() -> CFTypeID;
274 }
275 unsafe { SKSearchResultsGetTypeID() }
276 }
277}
278
279#[repr(transparent)]
281#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
282pub struct SKSearchType(pub c_uint);
283impl SKSearchType {
284 #[doc(alias = "kSKSearchRanked")]
285 pub const Ranked: Self = Self(0);
286 #[doc(alias = "kSKSearchBooleanRanked")]
287 pub const BooleanRanked: Self = Self(1);
288 #[doc(alias = "kSKSearchRequiredRanked")]
289 pub const RequiredRanked: Self = Self(2);
290 #[doc(alias = "kSKSearchPrefixRanked")]
291 pub const PrefixRanked: Self = Self(3);
292}
293
294#[cfg(feature = "objc2")]
295unsafe impl Encode for SKSearchType {
296 const ENCODING: Encoding = c_uint::ENCODING;
297}
298
299#[cfg(feature = "objc2")]
300unsafe impl RefEncode for SKSearchType {
301 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
302}
303
304#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
306pub type SKSearchResultsFilterCallBack =
307 Option<unsafe extern "C-unwind" fn(*mut SKIndex, *const SKDocument, *mut c_void) -> Boolean>;
308
309impl SKSearchGroup {
310 #[doc(alias = "SKSearchGroupCreate")]
315 #[deprecated = "No longer supported"]
316 #[inline]
317 pub unsafe fn new(
318 in_array_of_in_indexes: Option<&CFArray>,
319 ) -> Option<CFRetained<SKSearchGroup>> {
320 extern "C-unwind" {
321 fn SKSearchGroupCreate(
322 in_array_of_in_indexes: Option<&CFArray>,
323 ) -> Option<NonNull<SKSearchGroup>>;
324 }
325 let ret = unsafe { SKSearchGroupCreate(in_array_of_in_indexes) };
326 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
327 }
328
329 #[doc(alias = "SKSearchGroupCopyIndexes")]
330 #[deprecated = "No longer supported"]
331 #[inline]
332 pub unsafe fn indexes(&self) -> Option<CFRetained<CFArray>> {
333 extern "C-unwind" {
334 fn SKSearchGroupCopyIndexes(
335 in_search_group: &SKSearchGroup,
336 ) -> Option<NonNull<CFArray>>;
337 }
338 let ret = unsafe { SKSearchGroupCopyIndexes(self) };
339 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
340 }
341}
342
343impl SKSearchResults {
344 #[doc(alias = "SKSearchResultsCreateWithQuery")]
351 #[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
352 #[deprecated = "No longer supported"]
353 #[inline]
354 pub unsafe fn with_query(
355 in_search_group: Option<&SKSearchGroup>,
356 in_query: Option<&CFString>,
357 in_search_type: SKSearchType,
358 in_max_found_documents: CFIndex,
359 in_context: *mut c_void,
360 in_filter_call_back: SKSearchResultsFilterCallBack,
361 ) -> Option<CFRetained<SKSearchResults>> {
362 extern "C-unwind" {
363 fn SKSearchResultsCreateWithQuery(
364 in_search_group: Option<&SKSearchGroup>,
365 in_query: Option<&CFString>,
366 in_search_type: SKSearchType,
367 in_max_found_documents: CFIndex,
368 in_context: *mut c_void,
369 in_filter_call_back: SKSearchResultsFilterCallBack,
370 ) -> Option<NonNull<SKSearchResults>>;
371 }
372 let ret = unsafe {
373 SKSearchResultsCreateWithQuery(
374 in_search_group,
375 in_query,
376 in_search_type,
377 in_max_found_documents,
378 in_context,
379 in_filter_call_back,
380 )
381 };
382 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
383 }
384
385 #[doc(alias = "SKSearchResultsCreateWithDocuments")]
393 #[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
394 #[deprecated = "No longer supported"]
395 #[inline]
396 pub unsafe fn with_documents(
397 in_search_group: Option<&SKSearchGroup>,
398 in_example_documents: Option<&CFArray>,
399 in_max_found_documents: CFIndex,
400 in_context: *mut c_void,
401 in_filter_call_back: SKSearchResultsFilterCallBack,
402 ) -> Option<CFRetained<SKSearchResults>> {
403 extern "C-unwind" {
404 fn SKSearchResultsCreateWithDocuments(
405 in_search_group: Option<&SKSearchGroup>,
406 in_example_documents: Option<&CFArray>,
407 in_max_found_documents: CFIndex,
408 in_context: *mut c_void,
409 in_filter_call_back: SKSearchResultsFilterCallBack,
410 ) -> Option<NonNull<SKSearchResults>>;
411 }
412 let ret = unsafe {
413 SKSearchResultsCreateWithDocuments(
414 in_search_group,
415 in_example_documents,
416 in_max_found_documents,
417 in_context,
418 in_filter_call_back,
419 )
420 };
421 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
422 }
423
424 #[doc(alias = "SKSearchResultsGetCount")]
425 #[deprecated = "No longer supported"]
426 #[inline]
427 pub unsafe fn count(&self) -> CFIndex {
428 extern "C-unwind" {
429 fn SKSearchResultsGetCount(in_search_results: &SKSearchResults) -> CFIndex;
430 }
431 unsafe { SKSearchResultsGetCount(self) }
432 }
433
434 #[doc(alias = "SKSearchResultsGetInfoInRange")]
440 #[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
441 #[deprecated = "No longer supported"]
442 #[inline]
443 pub unsafe fn info_in_range(
444 &self,
445 in_range: CFRange,
446 out_documents_array: *mut *const SKDocument,
447 out_indexes_array: *mut *mut SKIndex,
448 out_scores_array: *mut c_float,
449 ) -> CFIndex {
450 extern "C-unwind" {
451 fn SKSearchResultsGetInfoInRange(
452 in_search_results: &SKSearchResults,
453 in_range: CFRange,
454 out_documents_array: *mut *const SKDocument,
455 out_indexes_array: *mut *mut SKIndex,
456 out_scores_array: *mut c_float,
457 ) -> CFIndex;
458 }
459 unsafe {
460 SKSearchResultsGetInfoInRange(
461 self,
462 in_range,
463 out_documents_array,
464 out_indexes_array,
465 out_scores_array,
466 )
467 }
468 }
469
470 #[doc(alias = "SKSearchResultsCopyMatchingTerms")]
471 #[deprecated = "No longer supported"]
472 #[inline]
473 pub unsafe fn matching_terms(&self, in_item: CFIndex) -> Option<CFRetained<CFArray>> {
474 extern "C-unwind" {
475 fn SKSearchResultsCopyMatchingTerms(
476 in_search_results: &SKSearchResults,
477 in_item: CFIndex,
478 ) -> Option<NonNull<CFArray>>;
479 }
480 let ret = unsafe { SKSearchResultsCopyMatchingTerms(self, in_item) };
481 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
482 }
483}
484
485#[cfg(feature = "SKIndex")]
486#[deprecated = "renamed to `SKSearch::new`"]
487#[inline]
488pub unsafe extern "C-unwind" fn SKSearchCreate(
489 in_index: Option<&SKIndex>,
490 in_query: Option<&CFString>,
491 in_search_options: SKSearchOptions,
492) -> Option<CFRetained<SKSearch>> {
493 extern "C-unwind" {
494 fn SKSearchCreate(
495 in_index: Option<&SKIndex>,
496 in_query: Option<&CFString>,
497 in_search_options: SKSearchOptions,
498 ) -> Option<NonNull<SKSearch>>;
499 }
500 let ret = unsafe { SKSearchCreate(in_index, in_query, in_search_options) };
501 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
502}
503
504extern "C-unwind" {
505 #[deprecated = "renamed to `SKSearch::cancel`"]
506 pub fn SKSearchCancel(in_search: &SKSearch);
507}
508
509#[cfg(feature = "SKIndex")]
510#[deprecated = "renamed to `SKSearch::find_matches`"]
511#[inline]
512pub unsafe extern "C-unwind" fn SKSearchFindMatches(
513 in_search: &SKSearch,
514 in_maximum_count: CFIndex,
515 out_document_i_ds_array: *mut SKDocumentID,
516 out_scores_array: *mut c_float,
517 maximum_time: CFTimeInterval,
518 out_found_count: *mut CFIndex,
519) -> bool {
520 extern "C-unwind" {
521 fn SKSearchFindMatches(
522 in_search: &SKSearch,
523 in_maximum_count: CFIndex,
524 out_document_i_ds_array: *mut SKDocumentID,
525 out_scores_array: *mut c_float,
526 maximum_time: CFTimeInterval,
527 out_found_count: *mut CFIndex,
528 ) -> Boolean;
529 }
530 let ret = unsafe {
531 SKSearchFindMatches(
532 in_search,
533 in_maximum_count,
534 out_document_i_ds_array,
535 out_scores_array,
536 maximum_time,
537 out_found_count,
538 )
539 };
540 ret != 0
541}
542
543extern "C-unwind" {
544 #[cfg(feature = "SKIndex")]
545 #[deprecated = "renamed to `SKIndex::copy_info_for_document_ids`"]
546 pub fn SKIndexCopyInfoForDocumentIDs(
547 in_index: &SKIndex,
548 in_count: CFIndex,
549 in_document_i_ds_array: *mut SKDocumentID,
550 out_names_array: *mut *const CFString,
551 out_parent_i_ds_array: *mut SKDocumentID,
552 );
553}
554
555extern "C-unwind" {
556 #[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
557 #[deprecated = "renamed to `SKIndex::copy_document_refs_for_document_ids`"]
558 pub fn SKIndexCopyDocumentRefsForDocumentIDs(
559 in_index: &SKIndex,
560 in_count: CFIndex,
561 in_document_i_ds_array: *mut SKDocumentID,
562 out_document_refs_array: *mut *const SKDocument,
563 );
564}
565
566extern "C-unwind" {
567 #[cfg(feature = "SKIndex")]
568 #[deprecated = "renamed to `SKIndex::copy_document_urls_for_document_ids`"]
569 pub fn SKIndexCopyDocumentURLsForDocumentIDs(
570 in_index: &SKIndex,
571 in_count: CFIndex,
572 in_document_i_ds_array: *mut SKDocumentID,
573 out_document_ur_ls_array: *mut *const CFURL,
574 );
575}
576
577#[deprecated = "renamed to `SKSearchGroup::new`"]
578#[inline]
579pub unsafe extern "C-unwind" fn SKSearchGroupCreate(
580 in_array_of_in_indexes: Option<&CFArray>,
581) -> Option<CFRetained<SKSearchGroup>> {
582 extern "C-unwind" {
583 fn SKSearchGroupCreate(
584 in_array_of_in_indexes: Option<&CFArray>,
585 ) -> Option<NonNull<SKSearchGroup>>;
586 }
587 let ret = unsafe { SKSearchGroupCreate(in_array_of_in_indexes) };
588 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
589}
590
591#[deprecated = "renamed to `SKSearchGroup::indexes`"]
592#[inline]
593pub unsafe extern "C-unwind" fn SKSearchGroupCopyIndexes(
594 in_search_group: &SKSearchGroup,
595) -> Option<CFRetained<CFArray>> {
596 extern "C-unwind" {
597 fn SKSearchGroupCopyIndexes(in_search_group: &SKSearchGroup) -> Option<NonNull<CFArray>>;
598 }
599 let ret = unsafe { SKSearchGroupCopyIndexes(in_search_group) };
600 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
601}
602
603#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
604#[deprecated = "renamed to `SKSearchResults::with_query`"]
605#[inline]
606pub unsafe extern "C-unwind" fn SKSearchResultsCreateWithQuery(
607 in_search_group: Option<&SKSearchGroup>,
608 in_query: Option<&CFString>,
609 in_search_type: SKSearchType,
610 in_max_found_documents: CFIndex,
611 in_context: *mut c_void,
612 in_filter_call_back: SKSearchResultsFilterCallBack,
613) -> Option<CFRetained<SKSearchResults>> {
614 extern "C-unwind" {
615 fn SKSearchResultsCreateWithQuery(
616 in_search_group: Option<&SKSearchGroup>,
617 in_query: Option<&CFString>,
618 in_search_type: SKSearchType,
619 in_max_found_documents: CFIndex,
620 in_context: *mut c_void,
621 in_filter_call_back: SKSearchResultsFilterCallBack,
622 ) -> Option<NonNull<SKSearchResults>>;
623 }
624 let ret = unsafe {
625 SKSearchResultsCreateWithQuery(
626 in_search_group,
627 in_query,
628 in_search_type,
629 in_max_found_documents,
630 in_context,
631 in_filter_call_back,
632 )
633 };
634 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
635}
636
637#[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
638#[deprecated = "renamed to `SKSearchResults::with_documents`"]
639#[inline]
640pub unsafe extern "C-unwind" fn SKSearchResultsCreateWithDocuments(
641 in_search_group: Option<&SKSearchGroup>,
642 in_example_documents: Option<&CFArray>,
643 in_max_found_documents: CFIndex,
644 in_context: *mut c_void,
645 in_filter_call_back: SKSearchResultsFilterCallBack,
646) -> Option<CFRetained<SKSearchResults>> {
647 extern "C-unwind" {
648 fn SKSearchResultsCreateWithDocuments(
649 in_search_group: Option<&SKSearchGroup>,
650 in_example_documents: Option<&CFArray>,
651 in_max_found_documents: CFIndex,
652 in_context: *mut c_void,
653 in_filter_call_back: SKSearchResultsFilterCallBack,
654 ) -> Option<NonNull<SKSearchResults>>;
655 }
656 let ret = unsafe {
657 SKSearchResultsCreateWithDocuments(
658 in_search_group,
659 in_example_documents,
660 in_max_found_documents,
661 in_context,
662 in_filter_call_back,
663 )
664 };
665 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
666}
667
668extern "C-unwind" {
669 #[deprecated = "renamed to `SKSearchResults::count`"]
670 pub fn SKSearchResultsGetCount(in_search_results: &SKSearchResults) -> CFIndex;
671}
672
673extern "C-unwind" {
674 #[cfg(all(feature = "SKDocument", feature = "SKIndex"))]
675 #[deprecated = "renamed to `SKSearchResults::info_in_range`"]
676 pub fn SKSearchResultsGetInfoInRange(
677 in_search_results: &SKSearchResults,
678 in_range: CFRange,
679 out_documents_array: *mut *const SKDocument,
680 out_indexes_array: *mut *mut SKIndex,
681 out_scores_array: *mut c_float,
682 ) -> CFIndex;
683}
684
685#[deprecated = "renamed to `SKSearchResults::matching_terms`"]
686#[inline]
687pub unsafe extern "C-unwind" fn SKSearchResultsCopyMatchingTerms(
688 in_search_results: &SKSearchResults,
689 in_item: CFIndex,
690) -> Option<CFRetained<CFArray>> {
691 extern "C-unwind" {
692 fn SKSearchResultsCopyMatchingTerms(
693 in_search_results: &SKSearchResults,
694 in_item: CFIndex,
695 ) -> Option<NonNull<CFArray>>;
696 }
697 let ret = unsafe { SKSearchResultsCopyMatchingTerms(in_search_results, in_item) };
698 ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
699}