1

I´m using Yapdatabase as storage engine in my iOS-application, and I need an index representing multiple values of the same property of an object.

Example: I´m storing car objects in my Yapdatabase. Most of my car objects have multiple colors, but I´d like to efficiently retrieve all yellow cars.

I´m somewhat familiar with YapDatabaseSecondaryIndexes, but I´ve not been able to fit that into my scenario.

How may I efficiently retrieve yellow cars?

stoffen
  • 570
  • 6
  • 14

1 Answers1

1

There are a couple options. If you're only dealing with a handful of colors, then you can still use YapDatabaseSecondaryIndex. You could configure your index to include a field for each color.

YapDatabaseSecondaryIndexSetup *setup = [[YapDatabaseSecondaryIndexSetup alloc] init];
[setup addColumn:@"red" withType:YapDatabaseSecondaryIndexTypeInteger];
[setup addColumn:@"blue" withType:YapDatabaseSecondaryIndexTypeInteger];
...

And then each car simply sets the "flags" for each color.

If you're dealing with a lot of different colors, then it may be more effective to use the FullTextSearch extension instead. Basically, you're going to create a string for each car that contains all the colors, and hand that string to the FullTextSearch extension. And then you can simply issue queries for cars that contain "yellow".

Robbie Hanson
  • 3,259
  • 1
  • 21
  • 16
  • My "colors-pool-size" is unknown at index-setup-time, but the full text search gave great performance. Thanks! – stoffen Mar 10 '16 at 06:44