如何在Couchdb中实现复杂的搜索过滤器?我应该避免使用临时视图吗? [英] How to realize complex search filters in couchdb? Should I avoid temporary views?

查看:71
本文介绍了如何在Couchdb中实现复杂的搜索过滤器?我应该避免使用临时视图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在网格中管理我的用户实体。我想对它们进行排序,并且希望为每列都具有一个搜索过滤器。

I want to administrate my User-entities in a grid. I want to sort them and I want to have a search filter for each column.

我动态生成的临时视图可以正常工作:

My dynamic generated temporary view works fine:

function(doc){
  if(doc.type === 'User' && 
    // Dynamic filters: WHERE firstName LIKE '%jim%' AND lastName LIKE '%knopf%'
    (doc.firstName.match(/.*?jim.*?/i) && 
    doc.lastName.match(/.*?knopf.*?/i)) ) {

    // Dynamic sort
    emit(doc.lastName, doc);
  }
}

但是到处都有,您必须避免使用临时视图。有没有更好的办法?我应该在运行时按需保存这些搜索吗?

BUT everywhere is written you have to AVOID temporary views. IS there a better way? Should I save these searches on demand at runtime?

谢谢

推荐答案

您绝对不应该使用临时视图,因为每次查询时都必须重新计算它们。 (这是一个非常昂贵的过程)当您提前知道要搜索的字段时,存储的视图就是完美的。 (它会一次建立索引,之后才进行增量更改)。

You should definitely not use temporary views, as they have to be recomputed every single time they are queried. (which is a very "expensive" process) A stored view is perfect when you know the fields you are searching ahead of time. (it builds the index one time, only making incremental changes after that)

但是,您将无法获得包含搜索。 (您可以获得完全匹配和开头为匹配,但这不是您的示例所显示的)如果您需要临时查询,则应认真考虑 couchdb-lucene

However, you won't be able to get "contains" searches. (you can get exact matches and "starts with" matches, but that's not what your example shows) If you need ad-hoc querying, you should seriously consider couchdb-lucene.

这篇关于如何在Couchdb中实现复杂的搜索过滤器?我应该避免使用临时视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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