Hi,
One more thing: you can not pass Parameters into the view ever. You have to 
create all items in a view via emit before there is one query actually running
What you can do, provided each document is small, is emit([no1, no2], null) for 
all no1 and no2 the document can potentially (!!!) match
Again: the document is doc, not 'this'
Plus don't emit the full doc as 2nd Param, That Most often just slows things 
down and is of no help. Null does it

Good luck - regards
    Sebastian

Von meinem iPhone gesendet

> Am 06.01.2015 um 13:43 schrieb Mic <[email protected]>:
> 
> Hi Sebastian,
> Thank you for your response. For the below documents I would like only get
> documents with the ids 7, 8 and 9, because chr.no = 5 and chr.no = 6
> (?key=[5,6]) only contains chr.letter between them which are not the same
> and do not have X.
> 
> Threfore I thought the judge function would be useful, but maybe in CouchDB
> is there a better way to do it.
> 
>    {
>      "total_rows":5,
>      "offset":0,
>      "rows":[
>        {
>          "_id":"10",
>          "_rev":"3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
>          "chr":[
>            {
>              "letter":"T",
>              "no":4
>            },
>            {
>              "letter":"A",
>              "no":5
>            },
>            {
>              "letter":"X",
>              "no":6
>            }
>          ]
>        },
>        {
>          "_id":"14",
>          "_rev":"3-21300d06c31224416b8ff71b71b304d8",
>          "chr":[
>            {
>              "letter":"T",
>              "no":4
>            },
>            {
>              "letter":"G",
>              "no":5
>            },
>            {
>              "letter":"G",
>              "no":6
>            }
>          ]
>        },
>        {
>          "_id":"7",
>          "_rev":"2-1516ba547bdd21724158bc854f39f66b",
>          "chr":[
>            {
>              "letter":"C",
>              "no":5
>            },
>            {
>              "letter":"T",
>              "no":6
>            }
>          ]
>        },
>        {
>          "_id":"8",
>          "_rev":"2-750078ccc9e74616f33a2537e41b8414",
>          "chr":[
>            {
>              "letter":"C",
>              "no":5
>            },
>            {
>              "letter":"T",
>              "no":6
>            }
>          ]
>        },
>        {
>          "_id":"9",
>          "_rev":"2-3d68352a2d98c56fd322ae674fb7c38a",
>          "chr":[
>            {
>              "letter":"A",
>              "no":5
>            },
>            {
>              "letter":"G",
>              "no":6
>            }
>          ]
>        }
>      ]
>    }
> 
> Best wishes,
> 
> Mic
> 
> On Tue, Jan 6, 2015 at 4:41 AM, Sebastian Rothbucher <
> [email protected]> wrote:
> 
>> Hi Mic,
>> 
>> the general misconception here seems to be that "this" within map refers to
>> the design doc, i.e. you'd have to have "chr" w/in the design doc - which
>> is not the case in the example you have given.
>> I think it would help to explain what you want to achieve with "judge" in
>> the first place...
>> 
>> Regards
>>     Sebastian
>> 
>>> On Thu, Jan 1, 2015 at 6:06 AM, Mic <[email protected]> wrote:
>>> 
>>> Hi Sinan,
>>> Thank you for the links and your suggestions. However, I did not quite
>>> understand your suggestions and I tried this map function which did not
>>> work:
>>> 
>>>    function(doc) {
>>>        var judge = function (no1, no2) {
>>>            var unexpect = "X";
>>>            var letter1 = unexpect, letter2 = unexpect;
>>>            for (var i in this.chr) {
>>>                var chr = this.chr[i];
>>>                if (chr.no == no1) {
>>>                    letter1 = chr.letter;
>>>                } else if (chr.no == no2) {
>>>                    letter2 = chr.letter;
>>>                }
>>>            }
>>>            if (letter1 != letter2 && letter1 != unexpect && letter2 !=
>>> unexpect) {
>>>                return true;
>>>            }
>>>            return false;
>>>        };
>>> 
>>> 
>>>      emit(judge(n1, n2), doc);
>>>    }
>>> 
>>> Could you please explain your ideas a little more?
>>> 
>>> Thank you in advance.
>>> 
>>> Mic
>>> 
>>> On Wed, Dec 31, 2014 at 10:57 PM, Sinan Gabel <[email protected]>
>>> wrote:
>>> 
>>>> Hi!
>>>> 
>>>> You may want to take a look at the basics here:
>>>> http://docs.couchdb.org/en/latest/couchapp/views/index.html and
>> Cloudant
>>>> has some interactive samples at:
>>>> https://cloudant.com/for-developers/all_docs/
>>>> 
>>>> *Using map*: You may want to emit the letters and use keys to find the
>>>> docs.
>>>> 
>>>> *Not using map*: Name each doc something "smart", and use keys to find
>>> the
>>>> docs.
>>>> 
>>>> Br,
>>>> Sinan
>>>> 
>>>>> On 31 December 2014 at 13:05, Mic <[email protected]> wrote:
>>>>> 
>>>>> Hi,
>>>>> I tried to create a map function which should use the following
>>>> conditions:
>>>>> 
>>>>> - e.g. chr.no = 5 and chr.no = 6
>>>>> - chr.letter between two objects/dicts in chr are not the same and
>> no
>>> X
>>>>> 
>>>>> I have the following function but I do not know how to combine it
>> with
>>>>> `emit`
>>>>> 
>>>>>    var judge = function (no1, no2) {
>>>>>        var unexpect = "X";
>>>>>        var letter1 = unexpect, letter2 = unexpect;
>>>>>        for (var i in this.chr) {
>>>>>            var chr = this.chr[i];
>>>>>            if (chr.no == no1) {
>>>>>                letter1 = chr.letter;
>>>>>            } else if (chr.no == no2) {
>>>>>                letter2 = chr.letter;
>>>>>            }
>>>>>        }
>>>>>        if (letter1 != letter2 && letter1 != unexpect && letter2 !=
>>>>> unexpect) {
>>>>>            return true;
>>>>>        }
>>>>>        return false;
>>>>>    };
>>>>> 
>>>>> 
>>>>> CouchDB has the below content:
>>>>> 
>>>>> 
>>>>>    {
>>>>>      "total_rows":5,
>>>>>      "offset":0,
>>>>>      "rows":[
>>>>>        {
>>>>>          "_id":"10",
>>>>>          "_rev":"3-5288068d2c4ef3e6a9d3f8ff4e3377dd",
>>>>>          "chr":[
>>>>>            {
>>>>>              "letter":"T",
>>>>>              "no":4
>>>>>            },
>>>>>            {
>>>>>              "letter":"A",
>>>>>              "no":5
>>>>>            },
>>>>>            {
>>>>>              "letter":"X",
>>>>>              "no":6
>>>>>            }
>>>>>          ]
>>>>>        },
>>>>>        {
>>>>>          "_id":"14",
>>>>>          "_rev":"3-21300d06c31224416b8ff71b71b304d8",
>>>>>          "chr":[
>>>>>            {
>>>>>              "letter":"T",
>>>>>              "no":4
>>>>>            },
>>>>>            {
>>>>>              "letter":"G",
>>>>>              "no":5
>>>>>            },
>>>>>            {
>>>>>              "letter":"G",
>>>>>              "no":6
>>>>>            }
>>>>>          ]
>>>>>        },
>>>>>        {
>>>>>          "_id":"7",
>>>>>          "_rev":"2-1516ba547bdd21724158bc854f39f66b",
>>>>>          "chr":[
>>>>>            {
>>>>>              "letter":"C",
>>>>>              "no":5
>>>>>            },
>>>>>            {
>>>>>              "letter":"T",
>>>>>              "no":6
>>>>>            }
>>>>>          ]
>>>>>        },
>>>>>        {
>>>>>          "_id":"8",
>>>>>          "_rev":"2-750078ccc9e74616f33a2537e41b8414",
>>>>>          "chr":[
>>>>>            {
>>>>>              "letter":"C",
>>>>>              "no":5
>>>>>            },
>>>>>            {
>>>>>              "letter":"T",
>>>>>              "no":6
>>>>>            }
>>>>>          ]
>>>>>        },
>>>>>        {
>>>>>          "_id":"9",
>>>>>          "_rev":"2-3d68352a2d98c56fd322ae674fb7c38a",
>>>>>          "chr":[
>>>>>            {
>>>>>              "letter":"A",
>>>>>              "no":5
>>>>>            },
>>>>>            {
>>>>>              "letter":"G",
>>>>>              "no":6
>>>>>            }
>>>>>          ]
>>>>>        }
>>>>>      ]
>>>>>    }
>>>>> 
>>>>> How is it possible to write a map function combine with the above
>>> `judge`
>>>>> function or maybe there is better way to do it?
>>>>> 
>>>>> P.S. I also asked the same question here (
>> http://stackoverflow.com/questions/27688196/map-function-with-a-helper-function-in-couchdb
>>>>> )
>>>>> 
>>>>> Thank you in advance.
>>>>> 
>>>>> Mic
>> 

Reply via email to