Vova Bilyachat
Vova Bilyachat

Reputation: 19494

Lucene.net and frequently update field

I have Content entity which is saved to database and Lucene for full text search. In that entities i have field Rating which is updated when user + or - rating. So rating can be updated any time and i need to show correct Rating value how to do it better? should i save rating to Lucene document and update it each time when user updates it?

Upvotes: 0

Views: 308

Answers (1)

Evereq
Evereq

Reputation: 1712

Usually approach is following:

  • store entity Id in Lucene, so you can easy load your entity from database or cache by this Id.
  • store entity fields by which you will do search, filtering or ordering. For example if you do search by username, store username. If you want to search by username and user bio, store both fields. But do not store for example user age or user phone if you don't need to do any search in this fields. Same with rating - if you do not need to search by rating (say you don't need to do queries like: search all users with rating > 100, or with rating != 0 etc) do NOT store rating in Lucene. Instead do search in Lucene, get entities Ids and then retrieve ratings from database or cache. This way you will need to update ratings in database only and update Lucene index only in case if few fields (like username or user bio) are changed.

Upvotes: 1

Related Questions