Yes I understand that now which is no longer an issue, however is the design of this index ok, would it scale well?
There will be thousands of new AudioCounter documents added daily.
Also, for the Weekly counters, in my index I am limiting the results by date for the last 7 days…is this good design?
I am just looking for approval on the way I am implementing this, or to see if there is a better alternative.
Thank You,
Paul
The same index code was posted on StackOverflow in a related question…
http://stackoverflow.com/questions/9035452/multimap-reduce-index-field-issue/9038753#9038753
where comment.CreatedAt >= DateTimeOffset.Now.AddDays(-7)
Ok, I understand that part.
But my query returns stats from several documents, both weekly and totals…if I query by that specific week how would it include the stats from each document and include the overall totals?
I need:
TotalComments
WeeksComments
TotalDownloads
WeeksDownloads
TotalPlays
WeeksPlays
And a few more…
Sorry if these are basic questions, it’s just something I haven’t wrapped my head around yet.
From: rav...@googlegroups.com [mailto:rav...@googlegroups.com] On Behalf Of Oren Eini (Ayende Rahien)
Sent: 01 March 2012 16:07
To: rav...@googlegroups.com
Subject: Re: [RavenDB] Re: Complex MulitMap / Reduce - From Stackoverflow
Inside your multi map, this gives you an output of 2012-15 (where 15 is the week number)
Struggling to get this to work how I want…
I have managed to get it working with 3 indexes.
1) Audio_Index
2) AudioStatsTotals_Index
3) AudioStatsWeekly_Index
I query my Audio_Index and filter on several properties, then query the 2 stats indexes and merge them together into my ViewModel, this works fine.
But I need to be able to OrderBy on the statistics, either on the weekly or total statistics but I can’t do this until I have merged them which is too late.
I have also tried to get a single index to work which just includes my weekly statistics, ignoring the total stats. Here is my index code:
This brings back incorrect results, they either have a NULL WeekNumber but with valid Audio properties, or a valid WeekNumber but null Audio properties.
Is this going to be possible, I really hope I can use some indexing magic rather than denormalize my statistic counters.
Sorry to be such a pain, I am 95% done re-writing my website to use RavenDb and I’m VERY happy so far, just apart from a couple of indexing issues, probably due to my lack of understanding.
Paul
Hi,
Thank you for taking the time to have a look at this, however I don’t think this will work for me as I also need to filter on properties of my Audio document, such as the AudioType or several other properties.
With the index you have provided, I will only have access to the properties of the statistics and the audio Id until I call ToList(), this isn’t going to work when I need to introduce paging & filtering on other properties.
Any other ideas?
I need to filter on the properties of my Audio document, however I need to order by on the aggregation properties which is the reason I was trying to get this all into a single index.
I have found a solution, not perfect but I think it will work.
In my AudioCounter document I have included a property called IsRecent, this is set to True when created.
I will then have a console application run once per hour to find all the AudioCounter documents older than 7 days where IsRecent = true, and update them to False, probably using a patch command.
This enables me to use my original index, but instead of comparing the Dates and using DateTime.Now.AddDays(-7) I can simply check for IsRecent = true.
As long as nothing stands out obvious why this is a bad idea, I’m happy to compromise with it.
Thank You,
Paul
Is what I have is hundreds and thousands of media files on my site, users can then play them, download them, like them, add them to favourites etc.
Each time they do this it’s logged down as a statistic, I then need the user to be able to view media of type ‘Mix’ and tagged with ‘Techno’, but also give them the option to order by the most downloaded in the past 7 days, the most played overall (since it was first uploaded) etc, the list of media are then displayed in pages to the user along with many properties from the Audio document such as name etc, the statistics for the past 7 days, and also that statistics since it was first uploaded.
If I am using 2 queries to get my data, how can I perform paging correctly. Forgive me if I am missing something but from the code you provided I don’t think it was possible, surely I need to perform my paging after I have done my filtering and my OrderBy, I can’t get the relevant audios as a list, then query their stats because I can’t OrderBy my stats correctly then.
The reason I can’t use the date in my index is because apparently (I’m not entirely sure why) I can’t use DateTime.Now inside my static index to compare against to filter my statistics to get a subset for only the last 7 days.
I may be making this sound more complex than it actually is, but from doing lots of Googling and plenty of tests and alterations this is the only way I can get it working.
I don’t want to filter by date, that’s pretty simple. I need to order by the stats that each Audio document has had in the past 7 days AND overall.
It doesn’t need to be PERFECTLY accurate, I have a page which lists the most popular audio, basically sorts Audio by how many downloads it has had in the last 7 days.
What I need in a simplified way (I have more stats than just downloads such as plays, comments, likes etc):
Audios
- Name
- AudioType
- Description
- Etc…
AudioDownloads
- AudioId
- DownloadDate
My index needs to include:
AudioIndex
- AudioId
- Name
- WeeksDownloads (a Sum of all the downloads from the AudioDownloads documents from the past 7 days only)
- TotalDownloads (a Sum of all the downloads from the AudioDownloads document)
Then I can perform filtering by Name, AudioType and also order by either WeeksDownloads or TotalDownloads very easily.
Sorry if I’m not expressing what I need very well.
Sounds good, will give it a go.
When you say update hourly, I take it you mean with a console application in the background.
Will updating every document in my index hourly affect my index performance in any way?
Thank you for the help, really appreciated!
Hi Oren,
I have implemented this for my weekly statistics and it’s working great thank you, should I follow the same principles for the Total statistics though?
Total statistics means it needs to include all AudioCounter documents for that AudioId rather than just from the previous 7 days, it means my Console app will need to query an index containing the totals every hour and will virtually include every Audio document (currently around 200,000), this is how I have set it up at the moment, I’m just hoping I don’t get any nasty performance issues later when in production?