Dexie.js: Search within tags

Created on 5 Jan 2017  路  2Comments  路  Source: dfahlander/Dexie.js

Is there any solution on how to use the filter or startsWith option to search within a field containing tags?
Within my dexie DB i have a field where the values are tags (one,two,three,four) per entry.

I tried to use the filter option but can not see how this would work out.
Anyone has an idea how it could be solved?
Greetings!

question

Most helpful comment

Don't know if I understand your question totally but generally, tags are best indexed using a multiEntry index. Then you put the tags in the indexed array property of your object. You can then search for objects of a certain tag using equals, equalsIgnoreCase, startsWith, startsWithIgnoreCase, anyOf or anyOfIgnoreCase.

var db = new Dexie ('dbname');
db.version(1).stores({
     items: 'id, *tags' 
}) ;
db.items.put({id: 1, tags: ['one',  'three']})
.then(function (){
    return db.items.where('tags').equals ('one')
       .distinct()
       .toArray();
}).then(function (items){
    console.table(items);
}).catch (function (err){
    console.error (err.stack || err);
});

All 2 comments

Don't know if I understand your question totally but generally, tags are best indexed using a multiEntry index. Then you put the tags in the indexed array property of your object. You can then search for objects of a certain tag using equals, equalsIgnoreCase, startsWith, startsWithIgnoreCase, anyOf or anyOfIgnoreCase.

var db = new Dexie ('dbname');
db.version(1).stores({
     items: 'id, *tags' 
}) ;
db.items.put({id: 1, tags: ['one',  'three']})
.then(function (){
    return db.items.where('tags').equals ('one')
       .distinct()
       .toArray();
}).then(function (items){
    console.table(items);
}).catch (function (err){
    console.error (err.stack || err);
});

Thanks a lot! I asked myself how people would do such manipulations via the "ordinary" indexeddb connection through javascript and quickly found the multientry option you mentioned.
As i never heared about it before, i searched for terms like "filter" or "contains" on dexie :)
Thanks again and wish you the best for this year - most importantly health !!!!

Was this page helpful?
0 / 5 - 0 ratings