You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by gateway0 <re...@yahoo.de> on 2009/04/08 18:53:23 UTC
Using constants with DataImportHandler and MySQL ?
Hi,
I tried to do the following in my "data-config.xml" file:
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/my_zend_appz" user="root" password=""/>
<document>
<entity name="ci_project" query="select pr_id, pr_name, pr_comment
from ci_project WHERE pr_id = 1">
<field column="pr_id" name="id" />
<field column="pr_name" name="name" />
<field name="definition">Projects</field> <--------------------Why
doesn´t that work?
<field column="pr_comment" name="comment" />
</entity>
</document>
</dataConfig>
The problem as you see is the line:
"<field name="definition">Projects</field>"
I want to set a constant value for every row in the SQL table but it doesn´t
work that way, any ideas?
kind regards,
Sebastian
--
View this message in context: http://www.nabble.com/Using-constants-with-DataImportHandler-and-MySQL---tp22954954p22954954.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Using constants with DataImportHandler and MySQL ?
Posted by gateway0 <re...@yahoo.de>.
Here´s the solution:
<entity name="ci_project" query="select pr_id, pr_name, pr_comment,
'dataci_project' from ci_project WHERE pr_id = 1">
<field column="dataci_project" name="definition" />
</entity>
just insert a dummy sql field 'dataci_project' in your select statement.
Glen Newton wrote:
>
> In MySql at least, you can do achieve what I think you want by
> manipulating the SQL, like this:
>
> mysql> select "foo" as Constant1, id from Article limit 10;
> select "foo" as Constant1, id from Article limit 10;
> +-----------+----+
> | Constant1 | id |
> +-----------+----+
> | foo | 1 |
> | foo | 2 |
> | foo | 3 |
> | foo | 4 |
> | foo | 5 |
> | foo | 6 |
> | foo | 7 |
> | foo | 8 |
> | foo | 9 |
> | foo | 10 |
> +-----------+----+
> 10 rows in set (0.00 sec)
>
> mysql> select 435 as Constant2, id from Article limit 10;
> select 435 as Constant2, id from Article limit 10;
> +-----------+----+
> | Constant2 | id |
> +-----------+----+
> | 435 | 1 |
> | 435 | 2 |
> | 435 | 3 |
> | 435 | 4 |
> | 435 | 5 |
> | 435 | 6 |
> | 435 | 7 |
> | 435 | 8 |
> | 435 | 9 |
> | 435 | 10 |
> +-----------+----+
> 10 rows in set (0.00 sec)
>
> mysql>
>
> 2009/4/8 Shalin Shekhar Mangar <sh...@gmail.com>:
>> On Wed, Apr 8, 2009 at 10:23 PM, gateway0 <re...@yahoo.de> wrote:
>>
>>>
>>> The problem as you see is the line:
>>> "<field name="definition">Projects</field>"
>>>
>>> I want to set a constant value for every row in the SQL table but it
>>> doesn´t
>>> work that way, any ideas?
>>>
>>
>> That is not a valid syntax.
>>
>> There are two ways to do this:
>> 1. In your schema.xml provide the 'default' attribute
>> 2. Use TemplateTransformer - see
>> http://wiki.apache.org/solr/DataImportHandlerFaq
>>
>> --
>> Regards,
>> Shalin Shekhar Mangar.
>>
>
>
>
> --
>
> -
>
>
--
View this message in context: http://www.nabble.com/Using-constants-with-DataImportHandler-and-MySQL---tp22954954p22969123.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Using constants with DataImportHandler and MySQL ?
Posted by Glen Newton <gl...@gmail.com>.
In MySql at least, you can do achieve what I think you want by
manipulating the SQL, like this:
mysql> select "foo" as Constant1, id from Article limit 10;
select "foo" as Constant1, id from Article limit 10;
+-----------+----+
| Constant1 | id |
+-----------+----+
| foo | 1 |
| foo | 2 |
| foo | 3 |
| foo | 4 |
| foo | 5 |
| foo | 6 |
| foo | 7 |
| foo | 8 |
| foo | 9 |
| foo | 10 |
+-----------+----+
10 rows in set (0.00 sec)
mysql> select 435 as Constant2, id from Article limit 10;
select 435 as Constant2, id from Article limit 10;
+-----------+----+
| Constant2 | id |
+-----------+----+
| 435 | 1 |
| 435 | 2 |
| 435 | 3 |
| 435 | 4 |
| 435 | 5 |
| 435 | 6 |
| 435 | 7 |
| 435 | 8 |
| 435 | 9 |
| 435 | 10 |
+-----------+----+
10 rows in set (0.00 sec)
mysql>
2009/4/8 Shalin Shekhar Mangar <sh...@gmail.com>:
> On Wed, Apr 8, 2009 at 10:23 PM, gateway0 <re...@yahoo.de> wrote:
>
>>
>> The problem as you see is the line:
>> "<field name="definition">Projects</field>"
>>
>> I want to set a constant value for every row in the SQL table but it
>> doesn´t
>> work that way, any ideas?
>>
>
> That is not a valid syntax.
>
> There are two ways to do this:
> 1. In your schema.xml provide the 'default' attribute
> 2. Use TemplateTransformer - see
> http://wiki.apache.org/solr/DataImportHandlerFaq
>
> --
> Regards,
> Shalin Shekhar Mangar.
>
--
-
Re: Using constants with DataImportHandler and MySQL ?
Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
On Wed, Apr 8, 2009 at 10:23 PM, gateway0 <re...@yahoo.de> wrote:
>
> The problem as you see is the line:
> "<field name="definition">Projects</field>"
>
> I want to set a constant value for every row in the SQL table but it
> doesn´t
> work that way, any ideas?
>
That is not a valid syntax.
There are two ways to do this:
1. In your schema.xml provide the 'default' attribute
2. Use TemplateTransformer - see
http://wiki.apache.org/solr/DataImportHandlerFaq
--
Regards,
Shalin Shekhar Mangar.