Questions about CSSearchQuery and Spotlight

I have added the contents of my app to iOS Spotlight via the CSSearchableItemAttributeSet and it is very easy to find them from spotlight in use. I'd like to achieve a similar effect in the app via CSSearchQuery, but I'm currently running into a problem.

In the system's spotlight, users can use fuzzy queries to find the information they want.

I can't enter Chinese characters in the forum, 'hello' should be Chinese characters

for example, if my content is in Chinese, 'hello', users can find the content not only by 'hello' but also by using 'nihao' to find the same content.('nihao' is the Latin pinyin equivalent of the Chinese word 'hello').

However, I am unable to achieve a similar effect in CKSearchQuery. At the moment CKSearchQuery only has [cdwt] four ways, is there any other means to achieve the above query capability. Or perhaps Apple does not have this capability open in CKSearchQuery.

I can't enter Chinese characters in the forum

I just tried this myself and also had problems. I’m not sure why this is failing because I’ve seen Chinese characters posted to DevForums previously. I’d appreciate you filing this as a bug against DevForums. Please post your bug number, just for the record.


Anyway, with regards your technical question, I don’t know exactly what the built-in Spotlight UI is doing but my experience in other contexts is that folks get around this by running multiple queries, one for the original text and one for the transliterated text.

You can transliterate Mandarin to pinyin using:

let han = "\u{4f60}\u{597d}"
let pinyin = han.applyingTransform(.mandarinToLatin, reverse: false) ?? "-"
print(pinyin)   // -> nǐ hǎo

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thank you for your reply. I have submitted feedback regarding the Chinese characters. FB9639611 In my own code, I have used a similar scheme to yours, fuzzy querying Chinese Latin spelling results from CoreData data.

extension String{

    func transformToLatin(hasBlank: Bool = false) -> String {

        let stringRef = NSMutableString(string: self) as CFMutableString

        CFStringTransform(stringRef,nil, kCFStringTransformToLatin, false) 

        CFStringTransform(stringRef, nil, kCFStringTransformStripCombiningMarks, false) 

        let pinyin = stringRef as String

        return hasBlank ? pinyin : pinyin.replacingOccurrences(of: " ", with: "")

    }

}

I will try again as you suggested.

Questions about CSSearchQuery and Spotlight
 
 
Q