Hi Maurizio,
if you can manipulate your MySql db a simpler solution can be the following:

1 - Add a new field for your hierarchical data inside your table
MY_HIERARCHICAL_FIELD
2 - Populate directly in MySql this new field with a simple procedure*
3 - Import the data in your Solr index

*The MySql procedure could be similar to the following:

1 - iterate your table and find your top records not yet elaborated (it
means with MY_HIERARCHICAL_FIELD empty and no father or with a father with
MY_HIERARCHICAL_FIELD NOT empty)
2 - find the anchestor of the founded records
3 - Update your  MY_HIERARCHICAL_FIELD field with the value of
MY_HIERARCHICAL_FIELD father || '/' || MY_ID current

At the end of the procedure you will have your MY_HIERARCHICAL_FIELD
populated with values like '12/35/45/154'
The value '12/35/45/154' means that the current record has id 154 and it is
a child of record 45 that is a child of 35 that is a child of 12 that has
no parents.




2012/10/2 Maurizio Cucchiara <mcucchi...@apache.org>

> Hi all,
> I'm trying to import some hierarchical data (stored in MySQL) on Solr,
> using DataImportHandler.
> Unfortunately, as most of you already knows, MySQL has no support for
> recursive queries, so there is no way to get hierarchical data stored
> as an adjacency list.
> So I considered writing a DIH custom transformers which given a
> specified sql (like select * from categories) and a value (f.e.
> category_id):
> * fetches all data
> * builds an hierarchical representation of the fetched data
> * optionally caches the hierarchical data structure
> * then returns 2 multi-valued lists which contain the 2 full paths (as
> String and as Number)
>
> Is there something out of the box?
> Alternatively, does the above approach sound good?
>
> TIA
>
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
> VisualizeMe: http://vizualize.me/maurizio.cucchiara?r=maurizio.cucchiara
>
> Maurizio Cucchiara
>

Reply via email to