Latest 1.0.3
Homepage https://github.com/paintingStyle/PSSearch
License MIT
Platforms ios 8.0
Dependencies PinYin4Objc
Authors

CI Status
Version
License
Platform

Example

联系人呢称/拼音/字母搜索组件

  • 支持汉字,字母,数字,下划线等搜索
  • 支持是否区分大小写搜索
  • 支持多音字匹配
  • 搜索结果优先展示 中文,其次是全拼匹配,最后是拼音首字母匹配
  • 优先显示 高亮位置索引靠前的搜索结果

使用方法

1, 初始化搜索数据源,指定搜索关键字与标识符

@property (nonatomic, strong) PSSearchManager *searchManager;

for (SPUser *aUser in category.friendsArray) {
    NSString *name = aUser.remark:aUser.nickname;
    NSString *identifer = [NSString stringWithFormat:@"%ld",[category.friendsArray indexOfObject:aUser]];
    [self.searchManager addInitializeString:name identifer:identifer];
}

#pragma mark - setter/getter

- (PSSearchManager *)searchManager {
    if (!_searchManager) {
        _searchManager = [[PSSearchManager alloc] init];
    }
    return _searchManager;
}

2, 匹配关键字,刷新结果列表

- (void)searchWithKeyWord:(NSString *)keyword{

NSMutableArray *resultDataSource = [NSMutableArray array];
for (PSSearchEntity *entity in [self.searchManager getInitializedDataSource]) {
        @autoreleasepool {
            PSSearchResult *result = [self.searchManager searchResultWithKeyWord:keyword searchEntity:entity];;
            if (!result.highlightedRange.length) { continue; } // 过滤无效的结果

            entity.highlightLoaction = result.highlightedRange.location;
            entity.textRange = result.highlightedRange;
            entity.matchType = result.matchType;
            if ([entity.identifier integerValue] <= self.allSearchFriendsArray.count-1) { // 根据标识符取出业务需要数据
                SPSelectModel *selectModel = self.category.friendsArray[[entity.identifier integerValue]];
                selectModel.highlightedRange = result.highlightedRange;
                [resultDataSource addObject:selectModel];
            }
        }
    }
self.hasSearchedArray = resultDataSource;
}

Requirements

Installation

PSSearch is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'PSSearch'

Author

paintingStyle, [email protected]

License

PSSearch is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "PSSearch",
    "version": "1.0.3",
    "summary": "u8054u7cfbu4ebau5462u79f0/u62fcu97f3/u5b57u6bcdu641cu7d22u7ec4u4ef6",
    "homepage": "https://github.com/paintingStyle/PSSearch",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "paintingStyle": "[email protected]"
    },
    "source": {
        "git": "https://github.com/paintingStyle/PSSearch.git",
        "tag": "1.0.3"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "PSSearch/Classes/**/*",
    "dependencies": {
        "PinYin4Objc": []
    }
}

Pin It on Pinterest

Share This