Haven't read the whole message (i will in a moment) but a quick answer would be did you try NH Search, or pure lucene indexing?
Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Thu, Mar 26, 2009 at 10:30 AM, Peter Morris <[email protected]> wrote: > > > Fabio gives the answer but do you really need to do it? > > Not sure :-) > > > I have a Song class which has a Name property. When the user searches for > a > song I want to list songs with a similar name to what they entered rather > than the exact string. To achieve this I am considering doing something > like > > 1: Remove all characters so I only have consonants (except for first > letters > of words) > 2: Remove all adjacent repeating letters > 3: Convert to lower case > 4: For each remaining word calculate a 32bit hash code > > For Song I will then have an association > Song 1---- *WordHash > > So > "My bonny lies over the occean" > would become > > my = 4622 > bny = 6732 > ls = 3623 > ovr = 3415 > th = 4312 > ocn = 1542 > > (Fake hash codes) > > Anyway, the point is that I can use a service to convert a string into a > collection of Int32 which I can use to create the associated hashes when > creating the song and also when searching for songs which might have a > similar name. I want to use a service obviously because it is used in 2 > places (create song, find song). > > Now my initial thought was to create a constructor for Song like so > > public Song(string name, int[] wordHashes) > { > ... > } > > and have a higher layer which creates the song also pass in the wordHashes, > but I am a bit of a control freak when it comes to code and this feels like > it is open to some other developer calling the constructor with the wrong > word hashes (I work with developers who would do this deliberately if it > was > a simple solution to an isolated problem). So another thought was > > public Song(string name, IWordHashService wordHashService) > { > ... > } > > but Unity IoC wont let me specify constants to pass to a constructor so > that's not an option (fake example).... > IoC.Resolve<Song>(new { Name = "My Bonnie lies over the occean" }) > > > > So then the next option > > public Song(string name) > { > ... > } > > [InjectionMethod] > public void InjectDependencies(IWordHashService wordHashService) > { > ... > } > > Obviously no good because the constructor will try to set the name before I > have the service. > > > Final option I can think of > > public class Song > { > .... > IWordHashService WordHashService; > > public Song() > { > } > > [InjectionMethod] > public void InjectDependencies(IWordHashService wordHashService) > { > WordHashService = wordHashService; > } > > private string name; > public string Name > { > get { return name; } > set > { > name = value; > //Calculate word hashes > } > } > } > > This would work and is the kind of thing I would normally do, but in my > current ORM I can mark a property so that it can no longer be updated once > persisted so I can use this approach and still make Name immutible. In NH > I > am trying to make my classes completely persistence ignorant so I need an > OOP way to make Name immutible, which is why I wanted to go for the Name in > the constructor, although I suppose I could throw an exception if you try > to > set Name when it already has a value. > > I'm looking forward to seeing some opinions, and maybe some alternative > ideas. > > > Pete > ==== > http://mrpmorris.blogspot.com > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
