PSSearch 1.0.9

PSSearch 1.0.9

Maintained by paintingStyle.



PSSearch 1.0.9

  • By
  • paintingStyle

PSSearch

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.