How to realize complex search filters in couchdb? Should I avoid temporary views?

丶灬走出姿态 提交于 2019-12-12 11:52:05

问题


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?

Thanks


回答1:


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)

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.



来源:https://stackoverflow.com/questions/6717323/how-to-realize-complex-search-filters-in-couchdb-should-i-avoid-temporary-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!