【发布时间】:2016-05-02 08:13:58
【问题描述】:
我有一个 Json 文档:
{
"_id": "3de00db35e6549604c711e7295a1982a",
"_rev": "1-ecba71644d341dfe5cb9abf6dd13b23a",
"dateCreated": "2014-01-29 00:00:00",
"attributeCollection": {
"attributeArray": [
{
"updateable": false,
"lookup": "issuetype",
"issueAttributeDefinitionId": 13,
"attributeType": 1,
"name": "Web Type",
"value": [
"Improper Limitation of Authentication"
]
},
{
"updateable": true,
"lookup": "status",
"issueAttributeDefinitionId": 1,
"attributeType": 4,
"name": "Status",
"value": [
"Access with Right Permission"
]
}
]
},
"hash": "287030d6efa085b5b92b7106c0edb6d7"
}
我想使用“名称”和“值”(仅限“名称”或“值”)为文档创建搜索索引。我通过以下代码访问了这些属性:
for (var i=0; i<doc.attributeCollection.attributeArray.length; i++) {
if (doc.attributeCollection.attributeArray[i].name) {
name = doc.attributeCollection.attributeArray[i].name;
}
if (doc.attributeCollection.attributeArray[i].value) {
value = doc.attributeCollection.attributeArray[i].value;
}
}
当我使用contentindex = name + " "+ value 时它可以工作;内容显示"Web Type Improper Limitation of Authentication"。但是,如果我只使用值contentindex = value,它不起作用,它显示为空。
我知道“值”的结构喜欢数组(1个元素的数组),它没有任何属性名称。
如何正确访问该值?
更新:
当我将某些情况索引为:
1.它有效
var content=name + " " + value;
index("default", content);
2。它有效
index("default", name);
3.它不起作用
index("default", value);
4.我通过修改代码来获得“价值”为:
if (doc.attributeCollection.attributeArray[i].value) {
for (var j=0; j<doc.attributeCollection.attributeArray[i].value.length; j++){
value = doc.attributeCollection.attributeArray[i].value[j];
}
}
或者
if (doc.attributeCollection.attributeArray[i].value) {
value = doc.attributeCollection.attributeArray[i].value[0];
}
它适用于index("default", value);
但是,当我使用this post 中讨论的置换函数时
5.它有效
var content= permuteword(name);
for(var k=0; k<content.length; k++){
index("default", content[k], { store : true });
}
6.它不起作用
var content= permuteword(value);
for(var k=0; k<content.length; k++){
index("default", content[k], { store : true });
}
7.它不起作用
var content=name + " " +value;
var content1= permuteword(content);
for(var k=0; k<content1.length; k++){
index("default", content1[k], { store : true });
}
【问题讨论】:
标签: json search indexing cloudant