问题
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