Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to index mysql database in solr using the Data Import Handler.

I have made two tables. The first table holds the metadata of a file.

create table filemetadata (
id varchar(20) primary key ,
filename varchar(50),
path varchar(200),
size varchar(10),
author varchar(50)
) ;

+-------+-------------+---------+------+---------+
| id    | filename    | path    | size | author  | 
+-------+-------------+---------+------+---------+
| 1     | abc.txt     | c:\files| 2kb  | eric    | 
+-------+-------------+---------+------+---------+
| 2     | xyz.docx    | c:\files| 5kb  | john    | 
+-------+-------------+---------+------+---------+
| 3     | pqr.txt     |c:\files | 10kb | mike    | 
+-------+-------------+---------+------+---------+

The second table contains the "favourite" info about a particular file in the above table.

create table filefav (
fid varchar(20) primary key ,
id varchar(20),
favouritedby varchar(300),
favouritedtime varchar(10),
FOREIGN KEY (id) REFERENCES filemetadata(id) 
) ;

+--------+------+-----------------+----------------+
| fid    | id   | favouritedby    | favouritedtime | 
+--------+------+-----------------+----------------+
| 1      | 1    | ross            | 22:30          | 
+--------+------+-----------------+----------------+
| 2      | 1    | josh            | 12:56          | 
+--------+------+-----------------+----------------+
| 3      | 2    | johny           | 03:03          | 
+--------+------+-----------------+----------------+
| 4      | 2    | sean            | 03:45          | 
+--------+------+-----------------+----------------+

here "id' is a foreign key. The second table is showing which person has marked which document as his/her favourite. Eg the file abc.txt represented by id = 1 has been marked favourite (see column favouritedby) by ross and josh.

I want to index the the files as follows:

each document should have the following fields

id       - to be taken from the first table filemetadata
filename - to be taken from the first table filemetadata
path     - to be taken from the first table filemetadata
size     - to be taken from the first table filemetadata
author   - to be taken from the first table filemetadata
Favouritedby - this field should contain the names of all the people from table 2 filefav (from the favouritedby column) who like that particular file.

eg after indexing doc 1 should have

id = 1
filename = abc.txt
path = c:\files
size = 2kb
author = eric
favourited by - ross , josh 

How Do I achieve this?

I have written a data-config.xml (which is not giving the desired result) as follows

<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/test" user="root" password="root" /> 
<document name="filemetadata">

<entity name="restaurant" query="select * from filemetadata">
<field column="id" name="id" /> 

 <entity name="filefav" query="select favouritedby from filefav where id=${filemetadata.id}">
<field column="favouritedby" name="favouritedby1" />
</entity>

<field column="filename" name="name1" /> 
<field column="path" name="path1" /> 
<field column="size" name="size1" /> 
<field column="author" name="author1" />  

</entity>
</document>
</dataConfig>

Can anyone explain how do i achieve this?

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.