Hello, I got a use case:
You may want to index only archived objects to restore them later by name. So one would expect something like this to work:
YapDatabaseSecondaryIndexWithObjectBlock block = ^(NSMutableDictionary *dict, NSString *collection, NSString *key, MYCategory *category) {
if ([category isKindOfClass:[MYCategory class]] && category.archived) {
dict[MYCategoriesIndexKeyDisplayName] = category.displayName;
}
};
Later, you query archived objects by MYCategoriesIndexKeyDisplayName, restore them by setting archived to NO, and automatically delete from the index. Unfortunately, this is impossible with current implementation.
Here is why:
The most likely you had set archived property later than the object was stored into the YapDatabase. As result, the SecondaryIndex only updates the row literally generating an UPDATE statement for SQLite without any effect in the table. Here is a workaround:
YapDatabaseSecondaryIndexWithObjectBlock block = ^(NSMutableDictionary *dict, NSString *collection, NSString *key, MYCategory *category) {
if ([category isKindOfClass:MYCategory.class] && category.archived) {
dict[MYCategoriesIndexKeyArchived] = @(category.archived);
dict[MYCategoriesIndexKeyDisplayName] = category.displayName;
}
};
The problem is that you have to keep an index for all categories potentially increasing search time. I believe it would be more effective to allow “partial” indexes and, as result, to reduce the number of rows in the index database table.
Not sure if this is a bug or a feature, so I updated the Wiki page.
Thanks,
Vadim
P. S. Maybe there is another way to solve this use-case?
Hello, I got a use case:
You may want to index only archived objects to restore them later by name. So one would expect something like this to work:
Later, you query archived objects by
MYCategoriesIndexKeyDisplayName, restore them by settingarchivedtoNO, and automatically delete from the index. Unfortunately, this is impossible with current implementation.Here is why:
The most likely you had set
archivedproperty later than the object was stored into the YapDatabase. As result, theSecondaryIndexonly updates the row literally generating anUPDATEstatement for SQLite without any effect in the table. Here is a workaround:The problem is that you have to keep an index for all categories potentially increasing search time. I believe it would be more effective to allow “partial” indexes and, as result, to reduce the number of rows in the index database table.
Not sure if this is a bug or a feature, so I updated the Wiki page.
Thanks,
Vadim
P. S. Maybe there is another way to solve this use-case?