Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8AA071058E for ; Mon, 22 Jul 2013 22:54:41 +0000 (UTC) Received: (qmail 97920 invoked by uid 500); 22 Jul 2013 22:54:38 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 97875 invoked by uid 500); 22 Jul 2013 22:54:38 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 97833 invoked by uid 99); 22 Jul 2013 22:54:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Jul 2013 22:54:38 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW X-Spam-Check-By: apache.org Received-SPF: error (athena.apache.org: local policy) Received: from [209.85.215.182] (HELO mail-ea0-f182.google.com) (209.85.215.182) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Jul 2013 22:54:32 +0000 Received: by mail-ea0-f182.google.com with SMTP id d10so4146797eaj.27 for ; Mon, 22 Jul 2013 15:53:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=djCWQXWfS4WIcc4cOoTOL7ooJ8fOSla1MAEgnUwgw28=; b=jjxZEEixp6qe4B3Qlxo3kYwr8a9j524jY55YwjtLntQ6bWUBg1YH/xWtIG67PCGkEB 8ZMYFML+050QU4loum4uV3u1meJ2Ak2Y5Aq9GvMCgUmyREExUASbOF7RKKce8rVA6Yuc YexNXP1VB4Zp+xMIbg275o74lsp2QMXviu4d2k1BuX7NPA+IwmdF9XJohIDQ0xpmSSUv sQVRjAwI9xRaHWpHPQ0fMB/aRkD9/SgkI1fbI4ObgFvTKLY1648ffpaB/gFjpM9UQj9w 7eerdDlJOj/hSDu6fFtxQIk50KPmUArUbEiEY7YLW2TByos4a8Uxkuoha7c9HdAYCXXf QB2g== X-Received: by 10.14.38.14 with SMTP id z14mr30042862eea.49.1374533631196; Mon, 22 Jul 2013 15:53:51 -0700 (PDT) Received: from [192.168.2.112] ([77.72.35.178]) by mx.google.com with ESMTPSA id cg12sm54309584eeb.7.2013.07.22.15.53.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Jul 2013 15:53:50 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1283) Subject: Re: Get the 20 posts, of the last seven days, ordered by number of hits From: Filippo Fadda In-Reply-To: <1EC6F8E4-19BE-4368-9B8E-9B9EA317BAD6@calftrail.com> Date: Tue, 23 Jul 2013 00:53:47 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <4BF6C96C-E49A-44BB-826C-A5BB7B35B0AA@programmazione.it> References: <565CA793-C9DA-4BFE-AB3E-17D9E9287A69@programmazione.it> <1EC6F8E4-19BE-4368-9B8E-9B9EA317BAD6@calftrail.com> To: user@couchdb.apache.org X-Mailer: Apple Mail (2.1283) X-Gm-Message-State: ALoCoQkF6RTba2wINIMhHdA8jGNGa3cJKqt7wEjIpAzwmHg5nZvwDBZ7BtMhdgiN4sP2RATbUppE X-Virus-Checked: Checked by ClamAV on apache.org Thanks for your answer. Unfortunately the post date can change, because = a document can be updated or revert to a draft state and then published = again. Anyway I can still map with emit(post.publishingDate, NULL) all the = posts, then I can get the posts of the last week, using startkey = parameter. Finally I can query another view emit(hit.postId, NULL) using = reduce =3D _count using as keys all the doc ids from the first query and = stale=3Dok. I can sort the results and limits them to 20. In a week I = will have maybe 300 posts, so I think should be fast enough. -Filippo On Jul 23, 2013, at 12:11 AM, Nathan Vander Wilt wrote: > If your "hit" document includes the post date, you could map with = `emit([hit.post_date, hit.post_id])` and reduce with `_count`. Then you = when queried with `?group=3Dexact` you would have total hits per post = and you could prune the results using startkey to last 7 days. You would = still need to order all the recent matches yourself before limiting to = 20 posts however. Assuming the number of posts in a week is not enormous = it seems reasonable. >=20 > hth, > -nvw >=20 >=20 > On Jul 22, 2013, at 10:32 AM, Filippo Fadda wrote: >=20 >> OK, this answered to my question: >>=20 >> = http://stackoverflow.com/questions/5571459/couchdb-view-query-with-multipl= e-key-values >>=20 >> It is never possible to query by criteria A and then sort by criteria = B in CouchDB. >>=20 >> So I have to get posts in a data range, then sort them by number of = hits myself. >>=20 >> -Filippo >>=20 >>=20 >>=20 >> On Jul 22, 2013, at 6:25 PM, Filippo Fadda wrote: >>=20 >>> Let's suppose I have a blog and I want display the popular posts, = where popular means: the 20 posts, of the last seven days, ordered by = number of hits. >>> To avoid conflicts I don't save the number of hits in the post = itself, but I emit a new document every time a generic user displays a = post. >>> Even using view collation I don't get a solution for this problem. >>>=20 >>> -Filippo >>=20 >=20