IndexedDB IDBKeyRange复合/多重索引不起作用 [英] IndexedDB IDBKeyRange Compound/Multiple Index not working

查看:546
本文介绍了IndexedDB IDBKeyRange复合/多重索引不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释为什么我的IDBKeyRange似乎只在第一列上进行过滤?

Can anyone explain why my IDBKeyRange only seems to be filtering on the first column?

我的索引定义如下:

osDrugs.createIndex("combined", ["name", "strength", "form", "packsize"], {unique: false});

我的查询大致如下:

var transaction = pimsDB.transaction("drugs");
var objectStore = transaction.objectStore("drugs");
var range = IDBKeyRange.bound([tmpName, tmpStrength, tmpForm, tmpPack],[tmpName+"z", tmpStrength + "z", tmpForm+"z", tmpPack+"z"]);
var index = objectStore.index("combined");
var request = index.openCursor(range);

我的结果似乎是从tmpName到tmpName +"z"进行过滤,但完全忽略了强度,形式和包装大小.

My results appear to be filtering from tmpName up to tmpName + "z" but completely ignoring the strength, form, and packsize.

任何人都可以看到我在做什么吗?

Can anyone see what I'm doing wrong?

哦,所有字段都存储为字符串....

Oh, all fields are stored as strings....

干杯

其他信息:

我用复合索引创建的另一个表似乎正在工作.这些表之间仅有的两个区别如下:

Another table that I created with a composite index appears to be working. The only two difference between these tables are as follows:

1)起作用的表在索引中仅具有2个属性. 2)在适用的表格中,这两个属性都是3属性主键的一部分.

1) The table that works only has 2 properties in the index. 2) In the table that works both properties are part of a 3 property primary key.

我已经通过使用Chrome中的资源"标签测试了它在此表上的适用性,该标签使我可以通过下限键过滤索引并返回数据.

I've tested that it works on this table by using the "Resources" tab in Chrome which allows me to filter an index by the lower bound key and return data.

更多其他信息:

经过更多测试,然后切换到FF以确保它不是Chrome,但我遇到了问题,我认为我已经找到了问题.我不相信搜索复合索引的工作方式符合我的期望...

After some more testing, and switching over to FF to make sure that it wasn't a chrome but I was experiencing I think I have found the problem. I don't believe searching that composite index works the way I was expecting...

IDBKeyRange实际上是一个范围...例如,当我输入

The IDBKeyRange is actually a range... It appears that when I enter, for example,

["PARA","500","TAB","32"] ["PARAz","500z","TABz","32z"]

["PARA","500","TAB","32"] ["PARAz","500z","TABz","32z"]

IndexedDB搜索从LB开始的第一个药物,并选择直到最后一个在上限处终止的药物.

IndexedDB searches for the first drug that starts at the LB, and selects everything up to the last drug that ends at the upper bound.

我相信,这就是为什么它设法选择始于任何价值的优势.实际上,它并没有过滤以"500"开头的优势,而是选择了药物中从"500"的第一个实例到最后一个实例之间的所有内容.

This, I believe, is why it's managing to select strengths that start with any value. It's not actually filtering for strengths that start "500",it's selecting everything between the first instance of "500" on a drug up to the last.

如果我的假设正确,则以下文章可能有点错误/误导(因为我认为用户想搜索矩形而不是范围:

If my assumption is correct, the following article is probably a bit wrong/misleading (as I believe the user wanted to search a rectangle and not a range:

在多个属性上建立索引的DB游标范围

任何人都可以确认我的发现并告诉我是否有一种方法可以实际搜索多个值上的IndexedDB吗?在以上文章的底部,有人提到了一个相交函数,我认为它可以起作用,但是当我在线搜索时,似乎不存在...

Can anyone confirm what I'm finding and tell me if there's a way I can actually search IndexedDB on multiple values? At the bottom of the article above, someone mentions an intersect function which I think would work but when I search online, it doesn't seem to exist...

干杯

推荐答案

我在以下位置发布了通用解决方案:

I've posted a generalized solution over at:

https://gist.github.com/inexorabletash/704e9688f99ac12dd336

简短的摘要是,您需要检查结果的每个维度,如果任何值超出该维度的范围,请跳至下一个可能的键.

The short summary is that you need to inspect each dimension of the result, and if any value is beyond the bounds for that dimension, skip ahead to the next plausible key.

这篇关于IndexedDB IDBKeyRange复合/多重索引不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆