Open yugaoxiang opened 2 years ago
您的邮件已经收到,我会尽快查阅,谢谢!Best Wishes!
This sounds like a SQLite problem, not so much a wrapper problem. I could be wrong though! If you want to narrow it down some (and provide examples that point to it being FMDB's fault) I can take a look.
///creat table
NSString *docuPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *dbPath = [docuPath stringByAppendingPathComponent:@"test_ftsQueue.db"];
FMDatabaseQueue *dbQueue = [FMDatabaseQueue databaseQueueWithPath:dbPath];
FMSimpleTokenizer *simpleTok = [[FMSimpleTokenizer alloc] initWithLocale:NULL];
[FMDatabase registerTokenizer:simpleTok withKey:@"simple"];
[dbQueue inDatabase:^(FMDatabase * _Nonnull db) {
[db installTokenizerModule];
NSString *fts = @"CREATE VIRTUAL TABLE IF NOT EXISTS t_person USING fts3(name, phone, score, tokenize=fmdb simple)";
BOOL result = [db executeUpdate: fts];
if (result) {
NSLog(@"create fts queue table success");
}
}];
self.fts_dbQueue = dbQueue;
self.dbQueue_simpleTok = simpleTok;
///Add data
[_fts_dbQueue inDatabase:^(FMDatabase * _Nonnull db) {
for (int i = 0; i < 1000; i++) {
NSString *name = i == 300 ? @"德玛西亚" : @"诺克萨斯";
BOOL result = [db executeUpdate:@"insert into 't_person'(name,phone,score) values(?,?,?)" withArgumentsInArray:@[[NSString stringWithFormat:@"%@%u",name,arc4random()%10000],@"13",@53]];
if (result) {
NSLog(@"insert into 't_person' success");
} else {
NSLog(@"insert %@", [db lastError]);
}
}
}];
[_fts_dbQueue inDatabase:^(FMDatabase * _Nonnull db) {
NSString *sql = [NSString stringWithFormat:@"select * from 't_person' where name MATCH '%@'",self.textFiled.text];
FMResultSet *result = [db executeQuery:sql];
NSMutableArray *arr = [NSMutableArray array];
while ([result next]) {
Student *person = [Student new];
// person.ID = [result intForColumn:@"docid"];
person.name = [result stringForColumn:@"name"];
person.phone = [result stringForColumn:@"phone"];
person.score = [result intForColumn:@"score"];
[arr addObject:person];
// NSLog(@"从数据库查询到的人员: %@ id: %ld",person.name, person.ID);
}
}];
Hello, Thank you for reply,here is my code, I think FDMB uses Apple's tokenizer, so some words cannot be searched, do you have any ideas to improve?
Hello, I'm using Simple tokenizer,I insert a thousand data contains“德玛西亚”,But when I used "亚" to search, I couldn't find any data,can you help me?