tags:

views:

45

answers:

3

I'm looking for a strategy to present a individual user's rating on a solr document. ie. Users get to put give a rating 1-5 on a document and I want to present that back to them as they search.

I can think of two general approaches.

  1. Store the ratings in my RDBMS and query it after getting solr results and merge the data in business logic.

  2. Somehow also store this rating info in solr so it comes back with the data for a given user. All I can think of is attributes names with the userid and a value of rating.

Assuming a large user base, I worry approach 2 could get out of hand. How "wide" can you go with a solr document? Can you put tens of thousands of attributes on a document? Would the performance impact still leave approach 2 better than a second hit on a sql db(approach 1)?

Are there other approaches I'm not thinking of?

A: 

A third option might be to add an additional Solr index that contains just the document id, user id and the score aattributed to that document by the user. It would then be very simple and rapid to query the score by document & user.

Jibberish
A: 

I've used approach number 1. Since the number of ratings is low (probably less than 1000) per user, I just cache all their ratings upon login and store in memory. Then, when showing the SOLR results, it is very quick to just apply the ratings where needed.

This saves you from having a database call for each result and doesn't bog down the server too much. Plus, when a user updates their ratings, you just update the DB and invalidate the cache. You don't have to make an UPDATE call to a SOLR document.

Aaron D
So far this looks like it'll work just fine. A query to solr immediately followed by a query to sql to bring in the unique user data. I can see maybe even replacing the unique data with solr itself, but I think it would still be two queries in order to keep the number of attributes on the core data limited.
kareem
A: 

I would go with number 2, and only periodically update the rating. That way you can blend in the rating into the relevancy score calculated by Solr.

I think it depends on if you are like Digg/Reddit, where the up/down voting drastically impacts what is shown, or if it's just another factor in scoring, like how new the document is. If it's just another factor, then update your document once a day, a week or once a month in the quiet hours....

Eric Pugh