Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 26901 invoked from network); 17 Aug 2009 22:14:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Aug 2009 22:14:02 -0000 Received: (qmail 39562 invoked by uid 500); 17 Aug 2009 21:12:20 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 39503 invoked by uid 500); 17 Aug 2009 21:12:20 -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 39493 invoked by uid 99); 17 Aug 2009 21:12:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Aug 2009 21:12:20 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [209.85.212.177] (HELO mail-vw0-f177.google.com) (209.85.212.177) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Aug 2009 21:12:12 +0000 Received: by vws7 with SMTP id 7so2755311vws.29 for ; Mon, 17 Aug 2009 14:11:51 -0700 (PDT) MIME-Version: 1.0 Sender: adam@hjksolutions.com Received: by 10.220.15.65 with SMTP id j1mr5420335vca.83.1250543511235; Mon, 17 Aug 2009 14:11:51 -0700 (PDT) In-Reply-To: References: Date: Mon, 17 Aug 2009 14:11:51 -0700 X-Google-Sender-Auth: fd4700038cca4297 Message-ID: Subject: Re: How to code an advanced search From: Adam Jacob To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Sun, Aug 16, 2009 at 1:29 AM, Fr=E9d=E9ric Malo = wrote: > For example, imagine a music database as iTunes. I would like to create a > script to query such as : > > Sort all songs by genre then album =A0: > - with 3 or 5 stars > - artist name matching "floyd" > - duration between 5 and 8 minutes > - heard last week (perhaps another couch database, logging user actions) > - .... > > All the parameters are optional. Users can choose to filter with only 2 o= r 5 > parameters. Other parameters should be added. The simple answer is "you can't get there from here", at least not like you are thinking. You have a couple of options: * Refactor each of those questions into a single view for each, with the key pointing to a list of songs that match. * As the user adds more options, you are actually adding an extra request for each view * Use the built in sorting to get the sort order * Query all the various required views and return the final result set This is following a similar pattern to the ones used by Full text search engines - you are using CouchDB to create the indexes for you, which return light-weight data that gets culled based on your requirements. Another option would be to actually put all this data into a full text engine, and use that. (Solr is a nice option here, and perhaps couchdb-lucene.) Don't be afraid to do a little more work on the systems that talk to CouchDB - often when you find yourself reaching for a Join, instead reach for multiple queries and doing the computation of the final match set yourself. Adam (I've seen a system that does just this, only with CDB indexes rather than CouchDB, do very complex queries and filtering against every hotel in America at very, very high speed.) --=20 Opscode, Inc. Adam Jacob, CTO T: (206) 508-4759 E: adam@opscode.com