2

I am trying to understand how to build a lucene index for data that has a 1 to many relation.

suppose I have a table for families with id and family name and a table of people with id, first name, and hobbies (which is free text).

how would I create a lucene index that will help me find families that have family members that their hobbies match the search query (as full text search) ?

I want to get each matching family just once (even if there are several family members that their hobbies are a hit for the query.

What If I also had a hobbies field on the family record it self (in addition to personal hobbies) and I wanted to get all the families that either match on the family hobby or on the hobby of on of the family members ?

epeleg
  • 10,347
  • 17
  • 101
  • 151

1 Answers1

1

You may treat families as documents that are composed of hobbies (terms). Index hobbies in a searchable field, no matter they are family hobbies or personal hobbies. For the rest of the fields just store them as additional fields.

zdepablo
  • 452
  • 3
  • 6
  • Just to clarify on your answer. As I found on some other answer on the site, It is possible to add the same field to a single document multiple times. so I could for example have a familyHobbies field which would be added once per each family hobby and a memberHobbies field which would be addded once per each hobby of each family member. – epeleg Jan 16 '12 at 08:12