Skip to content

Instantly share code, notes, and snippets.

@sergi
Last active August 29, 2015 14:03
Show Gist options
  • Save sergi/e93f05c2afd48027125d to your computer and use it in GitHub Desktop.
Save sergi/e93f05c2afd48027125d to your computer and use it in GitHub Desktop.
Ideas on using 'full-text-like' on IdexedDB

Alternatives to duplicating and indexing fields in Contacts Datastore

Grouping and indexing several fields in the Contacts Datastore requires some duplication, extra-processing and potential problems synchronizing data from the original datastore to the Contacts indexed one. The idea is to come up with alternatives, or at the very least minimize the amount of data that has to be duplicated.

In any case, we should minimize the amount of fields that are indexed to the essential ones. That is name-related, phone, etc. Fields that are likely to have many null values such as organization should not be indexed.

Full-text search

The idea here would be to take the fields we want to index and concatenate them in a string like "Sergi Mansilla Telenor +311234567" or similar. The key of that string would be the same as the key of the original contact, so that we know what the origin is.

When the user would search, we would normalize and match the input using full-text search. And whenever the original contact changes, we would just replace the whole string by the new one.

Unfortunately IndexedDB doesn't provide full text search (although it is planned for future releases). But we can get pretty close to full text search using range and direction of cursors. The performance of those is unknown to me, but I can't imagine it would be completely terrible on normal Contact Databases (up to, say, 2000 contacts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment