2016-07-25 4 views
5

का उपयोग कर इंडेक्सिंग सामग्री मेल ऐप में या संदेश ऐप में आप कोर स्पॉटलाइट खोज का उपयोग करके किसी भी संदेश की सामग्री खोज सकते हैं। इसके अलावा मैं OneNote ऐसा कर सकता हूं, इसलिए यह एपीआई में उपलब्ध होना चाहिए।कोर स्पॉटलाइट

हालांकि, इसके बारे में दस्तावेज लगभग कोई अस्तित्व नहीं है। मैं केवल देख सकता हूं कि CSSearchableItemAttributeSet में contentUrl है, लेकिन मैंने .txt फ़ाइल के NSUrl को सेट करने का प्रयास किया है और कुछ भी नहीं हुआ है। kUTTypeText और kUTTypeUTF8PlainText पर सामग्री टाइप करने की भी कोशिश की लेकिन कोई सुधार नहीं हुआ।

क्या कुछ विशिष्ट फ़ाइल प्रारूप आवश्यक है? या कुछ और करना चाहिए? बनाने और एक खोज करने योग्य अनुक्रमणिका करने के लिए आइटम जोड़ने की प्रक्रिया नीचे

+0

तो आपका डेटा संदेश है? वर्तमान में आप किस मूल्य को मूल्य निर्धारित कर रहे हैं? विषय या पाठ सामग्री? – Wain

+0

आप अपने ऐप में .txt फ़ाइल को सिर्फ डीप्लंक क्यों नहीं कर सकते हैं। मुझे पता है कि यह आपके मामले के लिए एक हैक होगा, लेकिन आपकी समस्या भी हल कर सकता है। डिप्लिंक करने के लिए, अद्वितीय पहचानकर्ता सेट करें और इसे '- (BOOL) एप्लिकेशन में प्राप्त करें: (यूआईएप्लिकेशंस *) एप्लिकेशन जारी रखें उपयोगकर्ता निष्क्रियता: (nonnull NSUserActivity *) उपयोगकर्ता सक्रियता बहाली हैंडलर: (nonnull शून्य (^) (NSArray * _Nullable)) बहाली हैंडलर {} 'में AppDelegate.m –

+0

@Wain, डेटा उपयोगकर्ता द्वारा संग्रहीत किया जाता है, इसलिए सिद्धांत में यह कोई भी पाठ हो सकता है, इसकी सामान्य लंबाई लगभग 5000 वर्ण है, हालांकि यह कोई लंबाई हो सकती है। मैंने शीर्षक और थंबनेल यूआरएल सेट किया है, अगर आइटम वेब से निकलता है तो मैं सामग्री स्रोत भी सेट करता हूं। –

उत्तर

6

Apple documentation on CoreSpotlight टूट जाता है:

  • एक CSSearchableItemAttributeSet वस्तु बना सकते हैं और गुण है कि आइटम आप अनुक्रमित करना चाहते वर्णन निर्दिष्ट करें।

  • आइटम का प्रतिनिधित्व करने के लिए एक CSSearchableItem ऑब्जेक्ट बनाएं। एक CSSearchableItem ऑब्जेक्ट में एक अद्वितीय पहचानकर्ता है जो आपको बाद में का संदर्भ देता है।

  • यदि आवश्यक हो, तो एक डोमेन पहचानकर्ता निर्दिष्ट करें ताकि आप एक साथ कई आइटम एकत्र कर सकें और उन्हें समूह के रूप में प्रबंधित कर सकें।

  • खोजने योग्य आइटम के साथ विशेषता सेट को संबद्ध करें।

  • सूचकांक में खोजने योग्य आइटम जोड़ें।

यहाँ एक त्वरित उदाहरण मुझे लगता है कि दिखाता है कि कैसे करने के लिए सूचकांक एक साधारण नोट वर्ग है:

class Note { 
    var title: String 
    var description: String 
    var image: UIImage? 

    init(title: String, description: String) { 
     self.title = title 
     self.description = description 
    } 
} 

फिर कुछ अन्य समारोह में, अपने नोट्स बनाने के लिए, प्रत्येक नोट के लिए एक CSSearchableItemAttributeSet बनाने के लिए, बनाने के एक अद्वितीय CSSearchableItem विशेषता सेट, और सूचकांक खोज योग्य आइटम के संग्रह से:

import CoreSpotlight 
import MobileCoreServices 

// ... 

// Build your Notes data source to index 
var notes = [Note]() 
notes.append(Note(title: "Grocery List", description: "Buy milk, eggs")) 
notes.append(Note(title: "Reminder", description: "Soccer practice at 3")) 
let parkingReminder = Note(title: "Reminder", description: "Soccer practice at 3") 
parkingReminder.image = UIImage(named: "parkingReminder") 
notes.append(parkingReminder) 

// The array of items that will be indexed by CoreSpotlight 
var searchableItems = [CSSearchableItem]() 

for note in notes { 
    // create an attribute set of type Text, since our reminders are text 
    let searchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String) 

    // If we have an image, add it to the attribute set 
    if let image = note.image { 
     searchableItemAttributeSet.thumbnailData = UIImagePNGRepresentation(image) 
     // you can also use thumbnailURL if your image is coming from a server or the bundle 
//  searchableItemAttributeSet.thumbnailURL = NSBundle.mainBundle().URLForResource("image", withExtension: "jpg") 
    } 

    // set the properties on the item to index 
    searchableItemAttributeSet.title = note.title 
    searchableItemAttributeSet.contentDescription = note.description 

    // Build your keywords 
    // In this case, I'm tokenizing the title of the note by a space and using the values returned as the keywords 
    searchableItemAttributeSet.keywords = note.title.componentsSeparatedByString(" ") 

    // create the searchable item 
    let searchableItem = CSSearchableItem(uniqueIdentifier: "com.mygreatapp.notes" + ".\(note.title)", domainIdentifier: "notes", attributeSet: searchableItemAttributeSet) 
} 

// Add our array of searchable items to the Spotlight index 
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems(searchableItems) { (error) in 
    if let error = error { 
     // handle failure 
     print(error) 
    } 
} 

यह उदाहरण मधुमक्खी है n AppCoda's How To Use Core Spotlight Framework in iOS 9 गाइड से अनुकूलित।

+0

मेरे पास कुछ टिप्पणियां थीं, लेकिन उन्हें हटा दिया और प्रयोग किया। इतने छोटे ईमेल (18600 वर्ण) में, हर शब्द खोजने योग्य नहीं है, जिसमें 'इस' जैसे आम भी शामिल हैं। मेरा मानना ​​है कि इसमें विवरण का उपयोग शामिल नहीं है और बहुत ही संभावित कीवर्ड भी शामिल नहीं है। क्या आप सहमत हैं? –

+0

@ इवानइसीन यह संभव है OneNote में सर्वनाम या अन्य ब्लैकलिस्ट वाले शब्दों की एक सूची है जो खोजने योग्य वस्तुओं की अनुक्रमणिका बनाने से पहले खोजने योग्य टेक्स्ट से छीन ली गई हैं। – JAL

संबंधित मुद्दे