Case insensitive search in indexed DB

Can someone please tell me if it is possible to do a case insensitive search in the indexeddb object store using index, openCursor and keyRange ....
I can make it case sensitive and managed to implement something using toUpperCase function, but there are so many different options that it is impossible to accomplish this ... Any help is appreciated ... Thanx ... Example of trying:

var transaction = db.transaction("products", IDBTransaction.READ_ONLY);
var store = transaction.objectStore("products");
var descIndex = store.index('Index1');
var boundKeyRangeUpper = IDBKeyRange.bound(request.term.toUpperCase(), (request.term.toUpperCase()+'Z'));
descIndex.openCursor(boundKeyRangeUpper).onsuccess = function (e) 

      

UPDATE
This is what I ended up with: Four ranges that cover the possibility as well, i.e. FA, fA, Fa, fa ... This is done only in the first letter, that is, "F"

var boundKeyRangeUpper = IDBKeyRange.bound(term.toUpperCase(), term.toUpperCase()+'Z'); var boundKeyRangeUpper2 = IDBKeyRange.bound(term.toUpperCase(), term.toUpperCase()+'z'); var boundKeyRangeLower = IDBKeyRange.bound(term.toLowerCase(), term.toLowerCase()+'z'); var boundKeyRangeLower2 = IDBKeyRange.bound(term.toLowerCase(), term.toLowerCase()+'Z');

The search results above are stored in a different Store object, but with their description in uppercase, hence FISH, FRUIT, FRESH SALAD ... Now if a letter is pressed after F, for example. The "r" search would look like this new object store, where everything is uppercase ... It's far from perfect, but it works and it fits my needs quickly ... Perhaps we end up with a random search on business, maybe not ...

+3


source to share


3 answers


I recommend changing the structure of the object store, this is by adding a column (i.e. properties for each object in the store) with the same key value BUT for uppercase, and then making that new property a key instead.

//object
var lang = {
    name: 'Javascript',
    keyName: '', //THE NEW PROPERTY - KEY OF THE OBJECTSTORE
    interest: 100
};

      

when you add an object to the store, change the new property with the uppercase name (or term or whatever) so that the object is:



//object
var lang = {
    name: 'Javascript',
    keyName: 'JAVASCRIPT', // NEW PROPERTY MODIFIED TO UPPERCASE OF OLD KEY
    interest: 100
};

      

then continue with your code.

+5


source


Dexie.js does an excellent job of unfeeling searches without an extra index.



+4


source


The reason why you see IndexedDB pointers are lexicographically sorted .

According to this paradigm, a> A, as opposed to alphabetical sorting , which is more like what you are looking for.

To achieve alphabetical sorting, you would need to cycle through all the records in your lexicographic view (until you get zero as event.target.result

in onsuccess

), add the results to the general global, and then, after lexicographic sort completes, return the alphabetical view of your general global.

+1


source







All Articles