CouchDB-带参数的查询 [英] CouchDB - Queries with params

查看:99
本文介绍了CouchDB-带参数的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CouchDB的新手,我知道我的心态在关系型数据库领域可能仍然太多,但是这里有:



似乎在Couch上查询全部通过视图完成。我读到临时视图的效率很低,应该在生产中避免使用。



所以我的问题确实是如何使用参数进行有效查询(因为视图不接受它们)。例如,如果我要使用Couch为博客网站提供动力,我必须为每个帖子创建一个新视图,相当于从id = 1的帖子中选择帖子。



<我知道我可以在查询旁边使用lucene对结果进行全文搜索,但这仅对文本内容有用,而对数字不起作用。



我很高兴创建大量静态视图,因为可以非常简单地动态创建这些视图。我担心的是,这不是应该使用Couch的方式,我缺少了一些东西。随时启发我。



干杯,克里斯。

解决方案

视图确实接受url参数,其中key是您要寻找的参数。您甚至可以限制获取和排序的行数。



您的视图可以通过任意JSON键索引。这意味着您可以创建一个视图来发出文档,例如[username docid] => doc。然后,您可以使用 http:// url / to / view?来查询此视图。 key = [用户名 docid]



您可以创建一个发出[username type date] => doc的视图。现在您可以获取某个日期之间的某个特定的所有文档(使用startKey和endKey url参数)。



您的博客示例是CouchDB非常适合的示例对于。实际上,我相信这是O'reilly即将出版的CouchDB书中的一个例子。



也就是说,某些查询不能仅由CouchDB轻松处理。 couchdb-lucene在这里可以提供帮助。不要以为那只是对全文搜索的好处。我一直在使用它对数据库运行常规的复杂查询,以取得良好的效果。


I'm new to CouchDB and I know my mindset is probably still too much in the relational DB sphere, but here goes:

It appears that querying on Couch is all done via Views. I read that temporary views are very inefficient and should be avoided in production.

So my question really is how would one do effective querying with parameters (as the views do not accept them). For example if I were to use Couch to power a blog site would I have to create a new view for each post equivalent to 'select post from posts where id=1'.

I understand that I can use lucene along side the querying to perfom a full text search on the results, but this is only really useful for textual content not numbers.

Im happy creating a boat load of static views as they can be created very simply on the fly. My worry is that this is not how Couch was supposed to be used and I'm missing something. Feel free to enlighten me.

Cheers, Chris.

解决方案

Views do accept url parameters, key being the one your are looking for. You can even limit how many rows you get and sort as well.

Your views can be indexed by arbitrary JSON keys. This means you can create a view that emits documents like so, [username docid] => doc. Then you can query this view with http://url/to/view?key=[username docid].

You could create a view that emits [username type date] => doc. Now you can get all documents of a certain between a certain date (using startKey and endKey url parameters).

Your example of the blog is one that CouchDB is particularly well suited for. In fact I believe it's an example in the upcoming CouchDB book from O'reilly.

That said, some kinds of queries are not easily handled by CouchDB alone. couchdb-lucene can help here. Don't assume that's it's only good for full text search. I've been using it to run general complex queries against the database to good effect.

这篇关于CouchDB-带参数的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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