0

We are using Lucene as the search server for data retrieval.

With this come certain complexities that I was unprepared for, not the least of which is managing relationships between objects.

I want to create a clean and simple POCO for our domain objects. These POCOs will contain related objects that I need for the UI, but no other fields (IDs defining these relationships, various other fields I simply don't need on the UI)

This means that I cannot directly translate Lucene's Hits collection into my UI-friendly POCOs and need some intermediary set of classes that will, at the least, contain IDs of related objects (stored in the same, or other indeces). I hesitate to call these DTO objects but for the sake simplicity I will call them that.

So I envision it working as follows:

  1. Perform query in Lucene -> Hits collection
  2. Iterate through Hits -> DTO collection
  3. DTO collection -> [service to retrieve related objects, compose a POCO] -> POCOs
  4. Render a UI using the shiny simple POCOs

My fear in doing so is that I'll end up with Anemic Domain Model ( http://www.martinfowler.com/bliki/AnemicDomainModel.html ).

Is this a valid concern or am I on the right path?

Yevgen Fesenko
  • 177
  • 1
  • 7

2 Answers2

1

I've ended up going the familiar to me pattern of a DTO. DTO has all the IDs - it is merely a CLR reflection of a record retrieved from Lucene.

I then map from DTO to a POCO in the service layer and use those objects to render the UI elements.

Does not feel slick, but it works.

Yevgen Fesenko
  • 177
  • 1
  • 7
0

Without any ID information in your POCOs, your design will likely suffer from anemia as there will just be an unconnected jumble of objects (which may not even fit all in memory at once). Also, it would seem to me that the lack of IDs would greatly interfere with caching and memoization (which help in not hitting the database every time you need an object). I have rarely had the luxury of assuming that all of my data will fit in memory all at once.

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29
  • I don't need to make them all fit at once, just the subset that I choose to retrieve from Lucene. Moreover, as far as I understand, Lucene's Hits collection is lazy-loaded, so until you enumerate over it, there no request made to the index. – Yevgen Fesenko Dec 05 '12 at 05:19