Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fts #829

Open
yugaoxiang opened this issue Jan 20, 2022 · 3 comments
Open

fts #829

yugaoxiang opened this issue Jan 20, 2022 · 3 comments

Comments

@yugaoxiang
Copy link

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?

@lzcuriosity
Copy link

lzcuriosity commented Jan 20, 2022 via email

@ccgus
Copy link
Owner

ccgus commented Jan 20, 2022

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.

@yugaoxiang
Copy link
Author

///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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants