Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23828] iOS10: Support new CSSearchQuery APIs

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-08-29T07:32:19.000+0000
Affected Version/sRelease 5.5.0
Fix Version/sRelease 5.5.0
ComponentsiOS
Labelsios10, qe-5.5.0, searchquery
ReporterEric Wieber
AssigneeHans Knöchel
Created2016-08-25T21:31:00.000+0000
Updated2017-01-23T18:49:56.000+0000

Description

In https://developer.apple.com/reference/corespotlight/cssearchquery, iOS 10 offers new API's for the CoreSpotlight framework. In detail, these are new attributes for the CSSearchQuery to query an attribute set by it's attribute name. Proposed API:
// The search-query
var searchQuery = Ti.App.iOS.createSearchQuery({
    queryString: "Searchable*",
    attributes: ["title", "displayName", "keywords", "contentType"]
});

// The event to be called when a new batch of items is found
searchQuery.addEventListener("founditems", function(e) {
    // Get found items with e.items
});

// The event to be called when the search-query completes
searchQuery.addEventListener("completed", function(e) {
    // Loop through your found items and access the searchable-item attribute-set
});

// Start the search-query (or use searchQuery.cancel()) to abort it
searchQuery.start();

Comments

  1. Hans Knöchel 2016-08-26

    Looks easy to expose and we can do that right next to the existing [Ti.App.iOS.SearchableAttributeSet](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App.iOS.SearchableItemAttributeSet) etc. -I will propose an API for it later today, probably on the Ti.App.iOS.SearchQuery namespace :-)- See the proposed API above.
  2. Hans Knöchel 2016-08-27

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/8276 PR (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8280 PR (5_5_X): https://github.com/appcelerator/titanium_mobile/pull/8281 Demo:
       var win = Ti.UI.createWindow({
           backgroundColor: "#fff"
       });
       var btn = Ti.UI.createButton({
           title: "Start search-query"
       });
       
       var searchItems = [];
       var itemAttr = Ti.App.iOS.createSearchableItemAttributeSet({
           itemContentType: Ti.App.iOS.UTTYPE_IMAGE,
           title: "Titanium Core Spotlight Tutorial"
       });
       
       itemAttr.contentDescription = "Tech Example \nOn: " + String.formatDate(new Date(), "short");
       itemAttr.keywords = ["Mobile", "Appcelerator", "Titanium"];
       itemAttr.displayName = "Hello world";
       
       var item = Ti.App.iOS.createSearchableItem({
           uniqueIdentifier: "my-id",
           domainIdentifier: "com.mydomain",
           attributeSet: itemAttr
       });
       searchItems.push(item);
       
       var indexer = Ti.App.iOS.createSearchableIndex();
       
       indexer.addToDefaultSearchableIndex(searchItems, function(e) {
           if (e.success) {
               Ti.API.info("Press the home button and now search for your keywords");
           } else {
               alert("Errored: " + JSON.stringify(e.error));
           }
       });
       
       btn.addEventListener("click", function() {
           // An array of found Ti.App.iOS.SearchableItem's
           var allItems = [];
       
           // The search-query
           var searchQuery = Ti.App.iOS.createSearchQuery({
               queryString: 'title == "Titanium*"',
               attributes: ["title", "displayName", "keywords", "contentType"]
           });
       
           // The event to be called when a new batch of items is found
           searchQuery.addEventListener("founditems", function(e) {
               for (var i = 0; i < e.items.length; i++) {
                   allItems.push(e.items[i]);
               }
           });
       
           // The event to be called when the search-query completes
           searchQuery.addEventListener("completed", function(e) {
               if (!e.success) {
                   alert(e.error);
               }
       
               for (var i = 0; i < allItems.length; i++) {
                   var attributeSet = allItems[i].attributeSet
                   var foundTitle = attributeSet.title
                   var foundDisplayName = attributeSet.displayName
       
                   Ti.API.info("title: " + foundTitle + ", displayName: " + foundDisplayName);
               }
           });
       
           // Start the search-query (or use searchQuery.cancel()) to abort it
           searchQuery.start();
       });
       
       win.add(btn);
       win.open();
       
  3. Chee Kiat Ng 2016-08-29

    CR and FT passed! PRs merged!
  4. Eric Wieber 2016-08-29

    Verified implemented, using: MacOS 10.12 (16A239m) Studio 4.7.1.201608190732 Ti SDK 5.5.0.v20160829003224 Appc NPM 4.2.7 Appc CLI 5.5.0-5 Xcode 8.0 (8S201h) Able to search for and properly return indexed app content. Tested using the sample code provided and modified versions of it. Searches return the correct information when searching through zero, one, or several apps who's content has been indexed previously.

JSON Source