在couchDB / Php中仅使用1或2个字符时查看查询为空

时间:2013-07-15 14:33:48

标签: php couchbase

使用php couchbase sdk,我有一个索引各种对象类型的视图。

直接点击视图返回结果没问题

http://127.0.0.1:8092/default/_design/dev_domain/_view/search?stale=false&connection_timeout=60000&limit=10&skip=0&startkey=%22S%22&endkey=%22S\u02ad%22

幸福地回归

{"total_rows":700,"rows":[
{"id":"TestCompany\\Model\\SampleObject\\b63008d6d65df09a6947a9c3ebb9f3137ed3c54ac3754a21ba2098d80537c3ef","key":"sam","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\f6b4119f7373edb6cfc7901702a2bb81b655834cd009cdfcaaafbaa1991f2cc4","key":"sam","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\b63008d6d65df09a6947a9c3ebb9f3137ed3c54ac3754a21ba2098d80537c3ef","key":"samp","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\f6b4119f7373edb6cfc7901702a2bb81b655834cd009cdfcaaafbaa1991f2cc4","key":"samp","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\b63008d6d65df09a6947a9c3ebb9f3137ed3c54ac3754a21ba2098d80537c3ef","key":"sampl","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\f6b4119f7373edb6cfc7901702a2bb81b655834cd009cdfcaaafbaa1991f2cc4","key":"sampl","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\b63008d6d65df09a6947a9c3ebb9f3137ed3c54ac3754a21ba2098d80537c3ef","key":"sample","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\f6b4119f7373edb6cfc7901702a2bb81b655834cd009cdfcaaafbaa1991f2cc4","key":"sample","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\b63008d6d65df09a6947a9c3ebb9f3137ed3c54ac3754a21ba2098d80537c3ef","key":"sampled","value":"SampleData"},
{"id":"TestCompany\\Model\\SampleObject\\f6b4119f7373edb6cfc7901702a2bb81b655834cd009cdfcaaafbaa1991f2cc4","key":"sampled","value":"SampleData"}
]
}

但是使用php sdk:

$test = $cb->view("dev_domain", "search",array("startkey"=>"s","endkey"=>"s"."\u02ad"));

没有结果,使用3个或更多键很好,即:

$test = $cb->view("dev_domain", "search",array("startkey"=>"sam","endkey"=>"sam"."\u02ad"));


Array

(

[total_rows] => 700

[rows] => Array

(

[0] => Array

(

[id] => Authentic\Model\SampleObject\b63008d6d65df09a6947a9c3ebb9f3137ed3c54ac3754a21ba2098d80537c3ef

[key] => sam

[value] => SampleData

)



[1] => Array

(

[id] => Authentic\Model\SampleObject\f6b4119f7373edb6cfc7901702a2bb81b655834cd009cdfcaaafbaa1991f2cc4

[key] => sam

[value] => SampleData

)


)



)

我无法弄清楚如何通过查尔斯(代理)管道sdk,所以没有运气调试..

2 个答案:

答案 0 :(得分:0)

这里的问题是\u02ad已经被JSON编码了,所以当你用PHP中的CouchDB SDK提供它时,它将被重新编码(可能是\\u02ad,这不会导致当它到达CouchDB本身时你想要的东西)。

您应该在字符串中包含文字Unicode字符,或者将您的unicode字符串包装在json_decode包装器中,以便在传递到SDK方法之前对其进行解码,例如:

"endkey"=>"s".json_decode('"\u02ad"')

请注意双引号序列周围的单引号。

答案 1 :(得分:0)

当天结束时,我的数据当然只被索引为3个字符及以上(如示例所示),所以我很糟糕。