Reputation: 1991
I have a MySql database from which I need to fetch data into Solr that is normalized in MySql over several tables. For example, I have an 'articles' table that have a 'companyId' column. 'companyIds' are linked to 'companyName' in a second table 'company'. So in order to be able to find articles by company name using Solr I need to denormalize when building the Solr index.
What is the easiest way to do this? Can denormalization be done in the data source configuration or do I need to denormalize prior to creating the index?
Feeding data using Solrj and normalizing while doing it seems to be the easiest method I can come up with at the moment (although it seems unnecessary if Solr has those features).
Upvotes: 1
Views: 495
Reputation: 1991
Ah, I found what I was looking for in the documentation for the data import handler. Queries on tables holding values of references found in the current table can be extracted using queries of 'child entities' like below.
The category name of the item is resolved by selecting from the category table using the category_id from the parent entity/query:
<entity name="item_category" query="select category_id from item_category where item_id='${item.id}'">
<entity name="category" query="select description from category where id = '${item_category.category_id}'">
<field column="description" name="cat" />
</entity>
</entity>
XML from here: http://wiki.apache.org/solr/DataImportHandler#Full_Import_Example
Upvotes: 1