如何在CouchDB上执行参数化查询 [英] How do I perform a parameterized query on CouchDB

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

问题描述

我想使用CouchDB为我存储一些数据,然后使用RESTful api调用来获取我需要的数据。我的数据库称为测试,我的文档都具有类似的结构,看起来像这样(其中hello_world是文档ID):

I would like to use CouchDB to store some data for me and then use RESTful api calls to get the data that I need. My database is called "test" and my documents all have a similar structure and look something like this (where hello_world is the document ID):

"hello_world" : {"id":123, "tags":["hello", "world"], "text":"Hello World"}
"foo_bar" :{"id":124, "tags":["foo", "bar"], "text":"Foo Bar"} 

我想做的是让我的用户发送一个查询,例如:例如,给我所有包含'hello world'字样的文档。我一直在使用视图但是看起来它们只允许我将其中一个或多个值移到map函数的键部分,这使我能够执行以下操作:

What I'd like to be able to do is have my users send a query such as: "Give me all the documents that contain the words 'hello world', for example. I've been playing around with views but it looks like they will only allow me to move one or more of those values into the "key" portion of the map function. That gives me the ability to do something like this:


http:// localhost:5984 / test / _design / search / _view / search_view?key = 你好

但是,这不允许我让我的用户指定y他们的查询字符串。例如,如果他们搜索 hello world,该怎么办。我必须做两个查询:一个用于 hello,一个用于 world,然后我必须编写一堆JavaScript以合并结果,删除重复项等等(糟糕!)。我真正想要的是能够执行以下操作:

But this doesn't allow me to let my users specify their query string. For example, what if they searched for "hello world". I'd have to do two queries: one for "hello" and one for "world" then I'd have to write a bunch of javascript to combine the results, remove duplicates, etc (YUCK!). What I really want is to be able to do something like this:


http:// localhost:5984 / test / _design / search / _view / search_view?term = hello world

http://localhost:5984/test/_design/search/_view/search_view?term="hello world"

然后在视图map / reduce函数中使用参数 hello world来查找所有同时包含 hello和 world的文档标签数组。 CouchDB甚至可以实现这种功能吗?

Then use the parameter "hello world" in the views map/reduce functions to find all the documents that contain both "hello" and "world" in the tags array. Is this sort of thing even possible with CouchDB? Is there another way to accomplish this inside a view that I'm not thinking of?

推荐答案

CouchDB视图不支持分面搜索或全文搜索或结果交集。长沙发-Lucene插件可让您完成所有这些操作。

CouchDB Views do not support facetted search or fulltext search or result intersection. The couchdb-lucene plugin lets you do all these things.

http://github.com/rnewson/couchdb-lucene/tree/master

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

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