Worklight :: JSONStore ::如何使用其他搜索字段 [英] Worklight :: JSONStore :: How to work with additional search fields

查看:111
本文介绍了Worklight :: JSONStore ::如何使用其他搜索字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Worklight6.2,但我有一个与JSONStores相关的小问题.

I'm using Worklight6.2 and I have a small problem related with JSONStores.

我的应用程序中有几个可以帮助我与第三方数据库上的关系模型相关. 为了正确使用此范例,我尝试使用多个搜索索引在商店内查找文档. 假设我有一家这方面的商店

I have several on my application to aid me relating to my relational model on a third party database. To properly work with this paradigm I'm trying to use several search indexes to find documents inside my store. Let's say I have a store with this aspect

var data = {GUID: 'XPTO-XPTZ-FOO', product_name= 'potatos'}

有时我想通过GUID访问我的对象,而另一些时候我想通过product_name访问它. 所以我会有一个

Sometimes I want to access my object by GUID some other times I want to access it by product_name. So I would have a

var searchField = {GUID: 'string'};
var additionalSearchField = {product_name: 'string'};

问题是,当我使用这个AdditionalSearchField时,找不到我的土豆.我想使用extraSearchField来避免JSONStore重新创建.

Thing is, when I use this additionalSearchField it doesn't find my potatos. I would like to use additionalSearchField to avoid JSONStore recreations.

我认为我没有按照预期的方式使用其他搜索字段,但我难以理解其概念.

I think that I'm not using additional Search Fields the way they were intended, but I'm having trouble wrapping my head about its concept.

摘自IBM文档:

其他搜索字段是已编入索引但不属于所存储JSON数据的一部分的键.这些字段定义了其索引(在给定的JSON集合中)的值的索引,可用于更快地进行搜索.

Additional search fields are keys that are indexed but that are not part of the JSON data that is stored. These fields define the key whose values (in a given JSON collection) are indexed and can be used to search more quickly.

http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.1.0/com.ibm.worklight.dev.doc/devref/r_jsonstore_search_fields.html

有人可以帮助我了解他们的工作方式吗?

Can someone help me understand how they work?

推荐答案

以下是用于创建键/值存储(例如

Here's an example of additional search fields being used to create a key/value store like localStorage.

var KEY_VALUE_COLLECTION_NAME = 'keyvalue';

var collections = {};

//Define the 'keyvalue' collection and use additional search fields
collections[KEY_VALUE_COLLECTION_NAME] = {
    searchFields : {},
    additionalSearchFields : { key: 'string' }
};

WL.JSONStore.init(collections);
//I skipped the success and failure callbacks

//The code bellow assumes that the 'keyvalue' collection has been initialized.

var value = 'myValue';
var key = 'myKey';
WL.JSONStore.get(KEY_VALUE_COLLECTION_NAME).add({key: value}, {additionalSearchFields: {key: key}});
//I skipped the success and failure callbacks

//The code bellow assumes that add has finished sucesfully.

WL.JSONStore.get(KEY_VALUE_COLLECTION_NAME).find({key: key}, {exact: true, limit: 1});
//Should call the success callback with something like this: 
//[{_id: 1, json: {value: 'myValue'}}]

看看商店的内部表示形式

Take a look at the internal representation of the store in the docs.

如果我们想象我们添加了searchField1searchField2而不是我上面使用的空对象,它将看起来像这样:

If we imagine we added searchField1 and searchField2 instead of the empty object I used above, it would look like this:

+-----+-----------------------------+--------------+--------------+----------------------------------------+
| _id | key (additionalSearchField) | searchField1 | searchField2 | json                                   |
+-----+-----------------------------+--------------+--------------+----------------------------------------+
| 1   | myKey                       | a            | b            | {searchField1: 'a', searchField2: 'b'} |
+-----+-----------------------------+--------------+--------------+----------------------------------------+

请注意,myKey key(附加搜索字段)的值不属于所存储的JSON对象.这就是为什么文档说:

Notice that myKey the value of the key (additional search field) is not part of the JSON object stored. That's why the documentation says:

其他搜索字段是已编入索引但未编入索引的键 存储的JSON数据的一部分.

Additional search fields are keys that are indexed but that are not part of the JSON data that is stored.

创建表后,没有简单的方法来更改表的列(即搜索字段和其他搜索字段).这就是您遇到此问题的原因:-2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH .要更改被索引的内容,您需要编写一些迁移代码,以将数据移动到新集合或使用removeCollectiondestroy API删除集合.

There's no easy way to change the columns of the table (i.e. search fields and additional search fields) once it has been created. That's why you run into this: -2 PROVISION_TABLE_SEARCH_FIELDS_MISMATCH. To change what is being indexed you need to write some migration code to move data to a new collection or remove the collection with the removeCollection or destroy APIs.

这篇关于Worklight :: JSONStore ::如何使用其他搜索字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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