couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Keith Gable <zi...@ignition-project.com>
Subject Re: Paging large result sets with sorting
Date Thu, 17 Mar 2011 18:15:25 GMT
I'd also add that you could have a view that omitted the day and
instead put the person's name in there, in which case it would be
sorted by month, but you'd have to include_docs=true to get the day of
the inspection unless you put it as the last index in the array. (for
example: [2011,3,"Keith",2])

On Thu, Mar 17, 2011 at 1:13 PM, Keith Gable <ziggy@ignition-project.com> wrote:
> Uh. This sounds simple?
>
> view: by_home_owner_name:
> if (doc.home_owner_name) { emit(doc.home_owner_name, 1); }
>
> view: by_inspection_date:
> if (doc.inspection_date) {
> var d = new Date(doc.inspection_date);
> emit ([ d.getFullYear(), d.getMonth() + 1, d.getDate() ], 1);
> }
>
> To look for all of my inspections:
> ...by_home_owner_name?key=Keith Gable
>
> To get all of the inspections for today:
> ...by_inspection_date?reduce=false&key=[2011,3,17]
>
> To get all of the inspections for this month:
> ...by_inspection_date?reduce=false&startkey=[2011,3,0]&endkey=[2011,3,{}]
>
>
> Combining the two:
>
> view: by_inspection_date_and_homeowner_name:
> if (doc.inspection_date && doc.homeowner_name) {
> var d = new Date(doc.inspection_date);
> emit ([ d.getFullYear(), d.getMonth() + 1, d.getDate(),
> doc.homeowner_name ], 1);
> }
>
> ...by_inspection_date_and_homeowner_name?reduce=false&startkey=[2011,3,0]&endkey=[2011,3,{}]
>
> Will result in:
> [2011,3,1,"Alice"]
> [2011,3,1,"Bob"]
> [2011,3,2,"Keith"]
>
>
> Does any of that not do what you want?
>
> On Thu, Mar 17, 2011 at 12:33 PM, Justin Walgran <jwalgran@azavea.com> wrote:
>> Assume a CouchDB storing and indexing housing inspection records. Each
>> inspection document as two important fields.
>>
>>  - Home owner name
>>  - Inspection date
>>
>> There are about 15,000 inspection documents generated per month.
>>
>> I need to quickly retrieve a list of inspections for January, sorted
>> by home owner name.
>>
>> The issue I am running into is the fact that the size of the result
>> set requires paging the data using limit and startkey. This would
>> required that the view key be the inspection date, which means the
>> results cannot be sorted by home owner name. The size of the data
>> means that pulling it all down to the client and sorting in the
>> browser is not performant.
>>
>> Is there a clever way to solve this problem?
>>
>>
>> Thanks,
>>
>> Justin
>>
>
>
>
> --
> Keith Gable
> A+ Certified Professional
> Network+ Certified Professional
> Web Developer
>



-- 
Keith Gable
A+ Certified Professional
Network+ Certified Professional
Web Developer

Mime
View raw message