2016-06-07 60 views
0

我已成功(有点)在我的iPhone应用程序中实现聚光灯索引,但某些搜索字符串似乎无法搜索。ios 9核心聚光灯搜索不适用于某些字符串CSSearchableItemAttributeSet

我创建每个CSSearchableItemAttributeSet作为类型kUTTypeText,我设置显示名称,标题为“D0010”。我还将关键字设置为包含“D0010”。 (有几百个数字,例如D0011,D0012 ......)

该应用程序完成索引时没有错误。

当我进入焦点搜索并键入“D0”时,我得到三个左右的结果,因为我继续键入“D001”,我没有得到任何结果。

有趣的是,如果我输入“0010”,我会得到确切的结果!

有没有人有任何想法是怎么回事?

部分客观C代码如下。

attributeSet.displayName = [[NSString alloc] initWithFormat:@"%@", [dataflow flowCounter]]; 

    attributeSet.title = [[NSString alloc] initWithFormat:@"%@", [dataflow flowCounter]]; 
    //Sounds similar to displayName but is not displayed to user 

    attributeSet.contentDescription = [[NSString alloc] initWithFormat:@"%@", [dataflow flowDescription]]; 

    attributeSet.keywords = @[[[NSString alloc] initWithFormat:@"%@", [dataflow flowCounter]],[[NSString alloc] initWithFormat:@"D%@", [dataflow flowNumber]],[dataflow flowCounter], attributeSet.displayName, attributeSet.contentDescription,[dataflow flowNumber],[dataflow flowCounter] ]; 



    CSSearchableItem *item1 = [[CSSearchableItem alloc] initWithUniqueIdentifier:[[NSString alloc] initWithFormat:@"DTC_%@", [dataflow flowNumber]] domainIdentifier:@"com.utiligroup" attributeSet:attributeSet]; 

........

[[CSSearchableIndex defaultSearchableIndex] indexSearchableItems:[self.spotlightsearch copy] 
               completionHandler: ^(NSError * __nullable error) { 
    if (error != nil){ 
     NSLog(@"Error"); 
    } 
    else { 
     NSLog(@"dataflows added "); 

回答

0

退下,我知道加入indexSearchableItems只有标记为索引(在完成处理,即使成功的回报)的项目,但我没有意识到相当长的时间需要ios来索引它们。

1天后,所有项目现在都可以搜索。

所以基本上只需要一些时间。